为什么Set-WMIInstance仅作为本地用户工作?

时间:2019-03-29 22:49:33

标签: powershell wmi

以域用户身份运行任何Set-WMIInstance powershell命令时,出现此错误。

CategoryInfo:InvalidOperation:(:) [Set-WmiInstance],COMException FullyQualifiedErrorId:SetWMICOMException,Microsoft.PowerShell.Commands.SetWmiInstance

这很有趣,因为大约一年前,当我使用此命令时,一切正常。我一年前从github提取了相同的源代码,但现在它无法运行。

我很难解决Set-WMIInstance在许多计算机上以提升的Powershell实例作为本地用户,而在许多计算机上没有以提升的Powershell实例作为域用户的情况。

######Code that generates the error
$computer = $env:COMPUTERNAME
$filterNS = "root\cimv2"
$wmiNS = "root\subscription"
$query = "SELECT * FROM __InstanceOperationEvent WITHIN 1 WHERE TargetInstance ISA 'Win32_LogicalDisk' AND TargetInstance.DriveType=2"
$filterName = "USB Whitelist Filter"
$consumerName = "USB Whitelist Consumer"
$scriptFileName = "C:\scripts\LaunchPowerShell.vbs"

# This is where the WMI filter is registered
$filterPath = Set-WmiInstance -Class __EventFilter `
 -ComputerName $computer -Namespace $wmiNS -Arguments `
  @{name=$filterName; EventNameSpace=$filterNS; QueryLanguage="WQL";
    Query=$query}




#####Error observed

writeErrorStream      : True
PSMessageDetails      : 
Exception             : System.Runtime.InteropServices.COMException (0x80042003)
                           at 
                        System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 
                        errorCode, IntPtr errorInfo)
                           at System.Management.ManagementObject.Put(PutOptions options)
                           at Microsoft.PowerShell.Commands.SetWmiInstance.ProcessRecord()
TargetObject          : 
CategoryInfo          : InvalidOperation: (:) [Set-WmiInstance], COMException
FullyQualifiedErrorId : SetWMICOMException,Microsoft.PowerShell.Commands.SetWmiInstance
ErrorDetails          : 
InvocationInfo        : System.Management.Automation.InvocationInfo
ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo : {0, 1}

我希望Set-WMIInstance命令可以作为域用户使用。

0 个答案:

没有答案