我们如何检查PowerShell v2.0是否安装在服务器列表中?

如何检查PowerShell v2.0是否安装在服务器列表中? 服务器列表是Windows Server 2003和Windows Server 2008的组合。一个vbscript或PS脚本将是美好的。

我知道默认情况下在Windows Server 2008中安装了PowerShell,尽pipe我只是想确保有人不打扰服务器。

经过挖掘,find了几处在我的环境中没有任何可用的地方,我才发现这一点。 这将适用于没有Powershell的系统,因此可用于其他registry扫描。

$hostA = “RemoteComputer” $cred = Get-Credential "domain\username" $RegPath = "SOFTWARE\Microsoft\PowerShell\1\PowerShellEngine" $ValueName = "PowerShellVersion" $tmp = $(gwmi -computername $hostA -class win32_service -Credential $cred | Where-Object { $_.Name -eq “RemoteRegistry” }) if ( $($tmp.State) -eq "Stopped") {$tmp.StartService()} $reg = Get-WmiObject -credential $Cred -List -Namespace root\default -computername $hosta | Where-Object {$_.Name -eq "StdRegProv"} $ref = ($reg.GetStringValue(2147483650,$RegPath,$ValueName)).sValue if ($ref -eq $null ) {Write-Host $hostA "doesn't have Powershell"} else {Write-Host $hostA "has Powershell version" $ref} 

编辑:环顾四周,事实certificate,如果远程registry服务没有运行,这将无法正常工作。 我添加了代码来检查远程registry,并开始如果停止。 根据您的域名设置, $cred = Get-Credential "domain\username"可以与-Credential $cred一起被删除。

编辑2:好的,我发现使用.OpenSubKey()的权限问题。 我将它切换到.GetValueKind(),因为我们所需要做的就是validation密钥是否存在。 希望这对你有用。 我没有权限在我的工作,以充分testing这个给你。

Edit3:由于我跨越了不受信任的域,因此我的环境中有许多权限问题。 我重写了上面的代码在我的环境中工作。 它远程工作,不需要安装Powershell。 让我知道,如果你有任何其他错误。

我会检查这个键HKEY_LOCAL_MACHINE \ SOFTWARE \微软\ PowerShell \ 1 \ PowerShellEngine \ powershellversion。