我有以下perl脚本来从不同的服务器获取站点信息。除了一台服务器外,该脚本工作正常。
#!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";
}
我可以使用Powershell为同一台服务器获取站点信息,但不能使用Perl。
Get-WmiObject -Impersonation impersonate -Authentication PacketPrivacy -ComputerName servername -Namespace root/WebAdministration -Query "select Name from Site" | Select-Object {$_.Name}
请问有人可以建议为什么Perl脚本不适用于一台服务器,而powershell适用于同一台服务器。