Powershell 调用在Win8(PS3.0)和Win7(PS2.0)上表现不同的WmiMethod

Powershell 调用在Win8(PS3.0)和Win7(PS2.0)上表现不同的WmiMethod,powershell,wmi,powershell-2.0,Powershell,Wmi,Powershell 2.0,我要复制粘贴一些代码在这里从一个答案,我刚刚做了一个SO的问题。我遇到的问题是,在使用windows 8PS3.0时,为什么Invoke WmiMethod在我的windows 7PS2.0计算机上返回错误。代码如下: #Username/Group to give permissions to $trustee = ([wmiclass]'Win32_trustee').psbase.CreateInstance() $trustee.Domain = "domainname" $truste

我要复制粘贴一些代码在这里从一个答案,我刚刚做了一个SO的问题。我遇到的问题是,在使用windows 8PS3.0时,为什么Invoke WmiMethod在我的windows 7PS2.0计算机上返回错误。代码如下:

#Username/Group to give permissions to
$trustee = ([wmiclass]'Win32_trustee').psbase.CreateInstance()
$trustee.Domain = "domainname"
$trustee.Name = "username"

#Accessmask values
$fullcontrol = 2032127
$change = 1245631
$read = 1179785

#Create access-list
$ace = ([wmiclass]'Win32_ACE').psbase.CreateInstance()
$ace.AccessMask = $fullcontrol
$ace.AceFlags = 3
$ace.AceType = 0
$ace.Trustee = $trustee

#Securitydescriptor containting access
$sd = ([wmiclass]'Win32_SecurityDescriptor').psbase.CreateInstance()
$sd.ControlFlags = 4
$sd.DACL = $ace
$sd.group = $trustee
$sd.owner = $trustee

#Arguments - Arguments: access, description, max. allowed, name, password, path, type(0 = drive/folder share)
Invoke-WmiMethod -Class Win32_Share -Name Create -ArgumentList @($sd, "TestDescription", 100, "TestName$", "", "C:\Test", 0)
Invoke WmiMethod在windows 7计算机上执行时返回错误,而在windows 8上正常工作。如果我用$null替换$sd access参数,它在win7上可以正常运行。错误是:

Invoke-WmiMethod <<<< -Class win32_share -name Create -ArgumentList @($sd, "TestDescription", 100, "TestName$", "", "C:\Test", 0) 
+ CategoryInfo : InvalidOperation: (:) [Invoke-WmiMethod], ManagementException + FullyQualifiedErrorId : InvokeWMIManagementException,Microsoft.PowerShell.Commands.InvokeWmiMethod' 
有人能帮我理解为什么调用WmiMethod在处理w8时不喜欢我在w7上的访问参数吗?如果我使用:[wmiclass]“Win32\u share”运行它,则它在这两个节点上都接受$sd。创建。。。。。使用它的定义:

PS C:\Windows> ([wmiclass]'win32_share').Create

OverloadDefinitions   
-------------------                                             
System.Management.ManagementBaseObject Create(System.String Path, System.String Name, System.UInt32 Type, System.UInt32 MaximumAllowed, System.String Description, System
.String Password, System.Management.ManagementObject#Win32_SecurityDescriptor Access)
PS C:\Windows> ([wmiclass]'win32_share').Create

OverloadDefinitions   
-------------------                                             
System.Management.ManagementBaseObject Create(System.String Path, System.String Name, System.UInt32 Type, System.UInt32 MaximumAllowed, System.String Description, System
.String Password, System.Management.ManagementObject#Win32_SecurityDescriptor Access)