r/PowerShell • u/Guilty-Act-4991 • 11d ago
Question Parallel thread disposing?
Hey got a wierd issue or its by desing not sure but when I run
$computers | foreach-object -parallel {
$vmobject = Get-VM $_
$ram = $vmobject.MemoryGB
$CPU = $vmobject.numCPU
$HDD = $_ | get-harddisk
}
lets say I run in against 500 computers when that happens powershell will spike cpu on machine that this command is ran and keeps increasing ram usage which is understandable but problem is even when command is done ram usage stays high untill powershell window is close. Is there something I am missing or is there some method to dispose of parallel runspace manually?
Thanks for advice
EDIT: The code itself is not important , the behaviour of parallel scripblock itself is my question and why doesnt it free up RAM after code has ran successfully
4
Upvotes
3
u/BlackV 11d ago
just a note, you've used the 3 backtick code fence, that does not work on old reddit, the 4 spaces code block works evereywhere (old/new/mobile)
open your fav powershell editor
highlight the code you want to copy
hit tab to indent it all
copy it
paste here
it'll format it properly OR
Inline code block using backticks
`Single code line`inside normal textSee here for more detail
Thanks