I want to remove all user-created variables at the start of a script.
Currently I am doing Remove-Variable -Name *
but it tries to delete all system variables as well, resulting in lot of error messages.
Any other way?
How to clear the PowerShell screen. As discussed earlier, the PowerShell clear screen action is supported by a function Clear-Host and its two aliases cls and clear.
To view all environment variables in the current PowerShell session, you can run the command: Get-ChildItem Env: This is equivalent to running the Set command in Cmd.exe. returns The ALLUSERSPROFILE variable is C:\ProgramData.
Since all the system variables are read-only or constant anyway you can just silence the errors:
Remove-Variable * -ErrorAction SilentlyContinue
But admittedly, you should probably exclude a few anyway:
Get-Variable -Exclude PWD,*Preference | Remove-Variable -EA 0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With