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

前端 未结 9 1684
暖寄归人
暖寄归人 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 18:53

    EDIT: Use stej's answer below. My own (partially incorrect) one is still reproduced here for reference:


    You can use

    Get-Variable foo -Scope Global
    

    and trap the error that is raised when the variable doesn't exist.

提交回复
热议问题