WMI查询随机访问被拒绝

时间:2016-12-09 19:39:40

标签: powershell wmi

为什么Win32_Service WMI查询随机失败并拒绝访问我的WMI查询。

我每天针对多个不同的域运行Win32_Service WMI查询。今天我发现一个DOMAIN中的查询失败,因为它被拒绝访问。当我在循环中运行查询时,它们会在我看起来随机的时候失败。它将成功运行,失败一次或两次,然后再次成功运行。到目前为止,我只看到这种情况发生在我正在检查的一个域中。

这是错误消息

Friday, December 09, 2016 2:33:26 PM
Get-WmiObject : Access is denied.
(Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
At C:\junk\Untitled2.ps1:23 char:22
+     $Service_Data =  Get-WmiObject `
+                      ~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Get-WmiObject], UnauthorizedAccessException
    + FullyQualifiedErrorId : System.UnauthorizedAccessException,Microsoft.PowerShell.Commands.GetWmiObjectCommand

这是我正在运行

的模板
$loopDelay = 60
$userName  = 'Domain1\LocalAdmin'
$pwd       = 'Password'

$Sec_Pwd   = $pwd | ConvertTo-SecureString -AsPlainText -Force
$Creds     = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $UserName, $Sec_Pwd

$Servers   = @()
$Servers  += "Server1.Domain1.org"
$Servers  += "Server2.Domain1.org"
$Servers  += "Server3.Domain1.org"
$Servers  += "Server4.Domain1.org"

while (1 -eq 1)
{
    Get-Date
    $Service_Data = Get-WmiObject -Credential $creds -ComputerName $Servers Win32_Service |
                    where {$_.Name -eq "JunkTest"} |
                    select SystemName, State, Status
    $Service_Data | Format-Table
    "<Ctrl><C> to quit"
    sleep 60
}

0 个答案:

没有答案