I wrote a PowerShell script which will loop thru all the sites in the web application and add Field internalname and title to the HashTable. So i pass this HashTable from one function to another. But i get an error when executing the script. It says that the Object doenst have the ContainsKey method. So actually there is a problem when i pass HashTable it becomes an object and not HashTable anymore.
Anyone know how could i solve this? When i try to define the type of the object which is passed it just says that the object cannot be converted to HashTable.
Here is the script code that i use:
function Manage($hashTable, $webs)
{
$hash=$hashTable
foreach($spWeb in $webs)
{
$spWebFields=$spWeb.Fields
$hash=AddHashes($hash, $spWebFiels)
$spWeb.Dispose()
}
}
function AddHashes($hash, $fields)
{
foreach($field in $fields)
{
$hasKey=$hash.ContainsKey($field.InternalName)
if($hasKey -eq $false)
{
$hash.Add($field.InternalName, $field.Title)
}
}
return $hash
}
foreach($sitecol in $sitecols)
{
Manage(@{}, $siteCol.AllWebs)
$siteCol.Dispose()
}