我正在尝试编写一个实用程序,它将是可扩展的,而不是硬编码各种类型的执行策略。使用Get-Command,我可以获取有关Set-ExecutionPolicy的一些信息,但无法获取参数类型Microsoft.Powershell.ExecutionPolicy的成员
(get-command set-executionpolicy).parameters.executionpolicy这就是我所能做的。我尝试过使用get-typedata,但是当传递Microsoft.Powershell.ExecutionPolicy给它时,它什么也不返回。
所以问题是:我如何枚举所有的执行策略类型?
发布于 2017-12-29 06:09:29
您有两个选择:
#1-与枚举对象属性交互:
[Microsoft.PowerShell.ExecutionPolicy] | Get-Member -Static -MemberType Property TypeName: Microsoft.PowerShell.ExecutionPolicy
Name MemberType Definition
---- ---------- ----------
AllSigned Property static Microsoft.PowerShell.ExecutionPolicy AllSigned {get;}
Bypass Property static Microsoft.PowerShell.ExecutionPolicy Bypass {get;}
Default Property static Microsoft.PowerShell.ExecutionPolicy Default {get;}
RemoteSigned Property static Microsoft.PowerShell.ExecutionPolicy RemoteSigned {get;}
Restricted Property static Microsoft.PowerShell.ExecutionPolicy Restricted {get;}
Undefined Property static Microsoft.PowerShell.ExecutionPolicy Undefined {get;}
Unrestricted Property static Microsoft.PowerShell.ExecutionPolicy Unrestricted {get;}#2-在v3中引入,与枚举本身交互(这是@PetSerAl评论的简短版本)
# Values()
[Microsoft.PowerShell.ExecutionPolicy].GetEnumNames()Unrestricted
RemoteSigned
AllSigned
Restricted
Restricted
Bypass
UndefinedV3之前的版本:
# Names()
[Enum]::GetValues('Microsoft.PowerShell.ExecutionPolicy')https://stackoverflow.com/questions/48013952
复制相似问题