79467190

Date: 2025-02-25 16:20:25
Score: 1.5
Natty:
Report link

https://stackoverflow.com/a/28741328/24355600

Here's, IMO, an ingenius way of implementing such cleanup. Start your script (I'm using after foreach-object start) with finding all variables, variabling them and clear everything but in the end.

Start:

$sysvars = get-variable | Select-Object -ExpandProperty name
$sysvars += 'sysvars'

End:

Get-Variable * | Where-Object { $_.name -notin $sysvars } | Remove-Variable
Reasons:
  • Blacklisted phrase (1): stackoverflow
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: NobleRogue