gpt4 book ai didi

powershell - 在Powershell中获取ExecutionPolicy的成员

转载 作者:行者123 更新时间:2023-12-02 23:38:47 24 4
gpt4 key购买 nike

我正在尝试编写一个可扩展的实用程序,而不是对各种类型的执行策略进行硬编码。使用Get-Command可以获取有关Set-ExecutionPolicy的一些信息,但无法获取参数类型Microsoft.Powershell.ExecutionPolicy的成员。

(get-command set-executionpolicy).parameters.executionpolicy

就我所知。我试过使用get-typedata,但是将Microsoft.Powershell.ExecutionPolicy传递给它时,它什么也不返回。

因此问题是:如何枚举所有执行策略类型?

最佳答案

您有两种选择:

#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
Undefined

v3之前的版本:
         # Names()
[Enum]::GetValues('Microsoft.PowerShell.ExecutionPolicy')

关于powershell - 在Powershell中获取ExecutionPolicy的成员,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48013952/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com