PowerShell是否支持PS模块中的私有静态变量

时间:2016-11-28 06:45:58

标签: powershell

PowerShell是否支持PowerShell模块中的私有静态变量(如C#中的私有静态变量)?如果是这样,我需要一个“特殊”的语法吗?

1 个答案:

答案 0 :(得分:1)

你应该看一下about_Scopes documentation

script范围:

 Script: 
        The scope that is created while a script file runs. Only
        the commands in the script run in the script scope. To
        the commands in a script, the script scope is the local
        scope.

另外值得一读 - 限制无范围:

Modules:
        You can use a Windows PowerShell module to share and deliver
        Windows PowerShell tools. A module is a unit that can contain
        cmdlets, scripts, functions, variables, aliases, and other useful
        items. Unless explicitly defined, the items in a module are not
        accessible outside the module. Therefore, you can add the module to
        your session and use the public items without worrying that the
        other items might override the cmdlets, scripts, functions, and other
        items in your session.


        The privacy of a module behaves like a scope, but adding a module
        to a session does not change the scope. And, the module does not have
        its own scope, although the scripts in the module, like all Windows
        PowerShell scripts, do have their own scope. 
相关问题