Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $GetChildItemSplat = @{
- Path = "C:\Temp"
- LiteralPath = ""
- Filter = "*.txt"
- Recurse = $True
- Depth = $null
- }
- #This will throw an exception telling you 'An error occurred while enumerating through a collection: Collection was modified; enumeration operation may not execute'
- $GetChildItemSplat.Keys |
- Where-Object -FilterScript {$GetChildItemSplat[$_] -eq $Null} |
- ForEach-Object -Process { $GetChildItemSplat.Remove($_) }
- #This will work
- Foreach($Key in $($GetChildItemSplat.Keys))
- {
- If($Null -eq $GetChildItemSplat[$Key] -or $GetChildItemSplat[$Key] -eq "")
- {
- $GetChildItemSplat.Remove($Key)
- }
- }
Add Comment
Please, Sign In to add comment