In PowerShell, how do I test whether or not a specific variable exists in global scope?

前端 未结 9 1694
暖寄归人
暖寄归人 2020-12-07 18:34

I\'m using PowerShell scripts for some UI automation of a WPF application. Normally, the scripts are run as a group, based on the value of a global variable. It\'s a littl

9条回答
  •  暖寄归人
    2020-12-07 19:16

    Test-Path can be used with a special syntax:

    Test-Path variable:global:foo
    

    This also works for environment variables ($env:foo):

    Test-Path env:foo
    

    And for non-global variables (just $foo inline):

    Test-Path variable:foo
    

提交回复
热议问题