当我在连接到远程计算机的计算机上执行简单的PowerShell查询时,我从PowerShell ISE中收到此类错误:
Get-WmiObject : Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
At line:8 char:43
+ $WmiOS = Get-WmiObject <<<< -Class Win32_OperatingSystem -ComputerName $targetComputer -credential $credential
+ CategoryInfo : NotSpecified: (:) [Get-WmiObject], UnauthorizedAccessException
+ FullyQualifiedErrorId : System.UnauthorizedAccessException,Microsoft.PowerShell.Commands.GetWmiObjectCommand
You cannot call a method on a null-valued expression.
At line:9 char:45
+ $WmiOS.ConvertToDateTime <<<< ($WmiOS.LastBootUpTime)
+ CategoryInfo : InvalidOperation: (ConvertToDateTime:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
但是,相同的查询将在我的其他团队成员的计算机(或任何其他计算机)上正常工作,而不会出现任何问题。
我们尝试执行的脚本示例:
$WmiOS = Get-WmiObject -Class Win32_OperatingSystem -ComputerName $targetComputer -credential $credential
$WmiOS.ConvertToDateTime($WmiOS.LastBootUpTime)
有任何想法吗?
最佳答案
尝试将以下标志添加到Get-WmiObject命令:
-Authentication PacketPrivacy -Impersonation Impersonate
关于powershell - 为什么远程计算机上的Powershell查询会引发访问被拒绝错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7043437/