wmi query not returning data for a specific server

907 views Asked by At

I have below perl script to get sites information from different servers. The script is working fine except for one server.

#!C:/perl/bin/perl
use strict;
use Win32::OLE('in');         # WMI access and optimised flags

use constant wbemFlagReturnImmediately => 0x10;
use constant wbemFlagForwardOnly => 0x20;

my $computer = "servername";

my $wmiWebObject = Win32::OLE->GetObject("WinMgmts:{impersonationLevel=impersonate,authenticationLevel=PktPrivacy}!//$computer/root/WebAdministration");
my $sites = $wmiWebObject->ExecQuery("SELECT Name from Site", "WQL", wbemFlagReturnImmediately | wbemFlagForwardOnly);
foreach my $site (in $sites) {
    print "\nSite Name : " . $site->{Name} . "\n";
}

I can get site information using Powershell for the same server but not with Perl.

Get-WmiObject -Impersonation impersonate -Authentication PacketPrivacy -ComputerName servername -Namespace root/WebAdministration -Query "select Name from Site" | Select-Object {$_.Name}

Please can someone suggest why Perl script is not working only for one server while powershell is working for the same server.

1

There are 1 answers

0
Mohammad Nadeem On BEST ANSWER

So I could resolve the issue by simply restarting the WMI service on the server. I found this article useful.