Guest User

Untitled

a guest
Sep 22nd, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. $GetChildItemSplat = @{
  2. Path = "C:\Temp"
  3. LiteralPath = ""
  4. Filter = "*.txt"
  5. Recurse = $True
  6. Depth = $null
  7. }
  8.  
  9. #This will throw an exception telling you 'An error occurred while enumerating through a collection: Collection was modified; enumeration operation may not execute'
  10. $GetChildItemSplat.Keys |
  11. Where-Object -FilterScript {$GetChildItemSplat[$_] -eq $Null} |
  12. ForEach-Object -Process { $GetChildItemSplat.Remove($_) }
  13.  
  14. #This will work
  15. Foreach($Key in $($GetChildItemSplat.Keys))
  16. {
  17. If($Null -eq $GetChildItemSplat[$Key] -or $GetChildItemSplat[$Key] -eq "")
  18. {
  19. $GetChildItemSplat.Remove($Key)
  20. }
  21. }
Add Comment
Please, Sign In to add comment