我似乎无法通过Powershell设置WMI ACL.调用
Invoke-WmiMethod -Name "SetSecurityDescriptor" -Path "__systemsecurity=@" -ArgumentList $acl.psobject.immediateBaseObject
Run Code Online (Sandbox Code Playgroud)
返回此异常:
Invoke-WmiMethod : Invalid method Parameter(s)
At line:1 char:17.
+ Invoke-WmiMethod <<<< -Name "SetSecurityDescriptor" -Path "__systemsecurity=@" -ArgumentList $acl.psobject.immediateBaseObject
+ CategoryInfo : InvalidOperation: (:) [Invoke-WmiMethod], ManagementException
+ FullyQualifiedErrorId : InvokeWMIManagementException,Microsoft.PowerShell.Commands.InvokeWmiMethod
Run Code Online (Sandbox Code Playgroud)
SetSecurityDescriptor只接受__SecurityDescriptor类型的一个参数,$acl我正在使用的对象本身-Arguments似乎没问题:
PS C:\Windows\system32> $acl | gm
TypeName: System.Management.ManagementBaseObject#\__SecurityDescriptor
Name MemberType Definition
---- ---------- ----------
ControlFlags Property System.UInt32 ControlFlags {get;set;}
DACL Property System.Management.ManagementObject#__ACE[] DACL ...
Group Property System.Management.ManagementObject#__ACE Group {...
Owner Property System.Management.ManagementObject#__ACE Owner {...
SACL Property System.Management.ManagementObject#__ACE[] …Run Code Online (Sandbox Code Playgroud) 随着Powershell 5引入OOP Classes支持,功能,脚本和模块的传统基于注释的 Powershell文档方法不再适用.Get-Help没有对类,方法或属性提供任何帮助,看起来它将保持这种方式.除此之外,Get-Help在尝试查找特定函数的信息时没有太多帮助,而实际上没有相关的模块或PowerShell脚本.
由于类对于更复杂的Powershell项目特别有用,因此对最新文档的需求比以往任何时候都更迫切.像Doxygen和Sandcastle帮助文件生成器这样的项目确实支持许多OO语言的帮助生成,但似乎无法处理Powershell代码.就让我们来看看在PoshBuild项目表明,它是针对.NET语言的项目,也和需要集成到Visual Studio生成过程,其中纯PowerShell代码没有.
还有PSDoc能够生成基于Get-Help输出的HTML或降价格式的模块文档,如果它支持类,这将是我想要的.
那么,如果有的话,我如何自动生成合理的文档
使用基于注释的帮助文档语法?
显然,Powershell Classes 不支持自定义 getter 和 setter 方法。
当检查从 Powershell v5 类构建的 Powershell 对象实例时,我们发现该类的定义将在对象实例中[type]Property创建隐藏方法[type]get_Property()和方法:[void]set_Property([type])
class myClass {
[int]$Property
}
[myClass]::new() | Get-Member -Force | Where-Object { $_.Name -like "*Property" }
Run Code Online (Sandbox Code Playgroud)
TypeName: myClass
Name MemberType Definition
---- ---------- ----------
get_Property Method int get_Property()
set_Property Method void set_Property(int )
Property Property int Property {get;set;}
Run Code Online (Sandbox Code Playgroud)
如果 getter/setter 方法对于使用运算符访问属性至关重要,=就像由and运算符.Equals([object])调用的方法一样,我们应该能够重载默认的 getter/setter 方法并看到它简单地工作:-eq-ne
class myClass {
[int]$Property
hidden [void]set_Property([int]$Property) {
$this.Property=$Property * …Run Code Online (Sandbox Code Playgroud)