Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Exception calling "Add" with "2" argument(s): "Item has already been added. Key in dictionary: '' Key being added: ''"

$
0
0

Hi, could someone explain this error to me, script segment works, this is just odd.

Exception calling "Add" with "2" argument(s): "Item has already been added. Key in dictionary: ''  Key being added: ''"
At D:\bhav\test7.ps1:20 char:15
+         $tmpHash.Add <<<< ($tmpKey,$tmpValue)
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

#
$CurrentDir = get-location
$txt1 = $CurrentDir.Path + "\netsh.txt"
$oldtxt1 = $CurrentDir.Path + "\netsh.txt"
remove-item $oldtxt1 -ErrorAction:SilentlyContinue
$x = netsh int tcp show global 
$y = $x | out-string 
$y | Out-File -Filepath $txt1
(gc $txt1|where {$_.readcount -lt 1 -or $_.readcount -gt 4})| set-content $txt1
#
$tmpStr = gc $txt1
	$tmpArr = $tmpStr
	$tmpHash = @{}
	foreach($tmpArrEntry in $tmpArr)
		{
		$tmpKey = $tmpArrEntry.Split(':')[0]
		$tmpValue = $tmpArrEntry.Split(':')[1]
		# $tmpHash.Add($tmpKey.Trim(),$tmpValue.Trim())
		$tmpHash.Add($tmpKey,$tmpValue)
	}
	Write-output $tmpHash


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>