powershell - Remove all variables

后端 未结 8 780
礼貌的吻别
礼貌的吻别 2020-12-31 05:05

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 dele

8条回答
  •  清歌不尽
    2020-12-31 05:35

    You should not rely on those variables. Anything that was not declared is just not used. If you need to pass things around, use parameters.

    If you keep up to this principle, you would just overwrite your user-created variable and use it like it never existed.

    This is enterprise best practices that let you infinitely scale your scripts. Not just in Powershell, but in any language which could have global variables, such as Javascript.

提交回复
热议问题