private/Copy-HashTable.ps1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
function Copy-HashTable{ param([hashtable]$hash, [String[]]$include, [String[]]$exclude) if($include){ $newhash=@{} foreach ($key in $include){ if ($hash.ContainsKey($key)){ $newhash.Add($key,$hash[$key]) | Out-Null } } } else { $newhash=$hash.Clone() if ($exclude){ foreach ($key in $exclude){ if ($newhash.ContainsKey($key)) { $newhash.Remove($key) | Out-Null } } } } return $newhash } |