How can we check PowerShell v2.0 is installed on a list of servers?

After digging around and finding several places that lead to nothing usable in my environment, I was able to find this. This will work on systems that don't have Powershell, so it could be used for other registry scans.

$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}

Edit: After looking around, it turns out this won't work if the Remote Registry service isn't running. I added code to check for remote registry and start if stopped. The $cred = Get-Credential "domain\username" can be removed along with -Credential $cred depending on your domain setup.

Edit2: Ok, I have found permission issues with using .OpenSubKey(). I am switching it to .GetValueKind(), since all we need to do is verify the key exist. Hopefully this works for you. I don't have the permissions where I work to fully test this for you.

Edit3: I was having a lot of problems with permission in my environment since I cross untrusted domains. I have rewrote the above code to work in my environment. It works remotely, and doesn't require Powershell to be installed. Let me know if you get any other errors.


I'd check this key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\PowerShellEngine\powershellversion.