How to know if powershell is installed on remote workstation?
check if file exist ?
$path= "\\remote\C$\windows\System32\WindowsPowerShell\v1.0\powershell.exe"if(test-path $path){(ls $path).VersionInfo}
You could use a batch-script that you run manually or try using GPO(as a startup script). It will save a file my-computer-name.txt
with "false" if powershell wasn't found or the PS-version(1.0 or 2.0) if PS is installed. Then you'd just read the files.
pscheck.bat
@echo offFOR /F "tokens=3" %%A IN ('REG QUERY "HKLM\SOFTWARE\Microsoft\PowerShell\1" /v Install ^| FIND "Install"') DO SET PowerShellInstalled=%%AIF NOT "%PowerShellInstalled%"=="0x1" (echo false > \\remote\location\%COMPUTERNAME%.txtGOTO end)FOR /F "tokens=3" %%A IN ('REG QUERY "HKLM\SOFTWARE\Microsoft\PowerShell\1\PowerShellEngine" /v PowerShellVersion ^| FIND "PowerShellVersion"') DO SET PowerShellVersion=%%Aecho %PowerShellVersion% > \\remote\location\%COMPUTERNAME%.txt:end
The PSversion value for 3.0 in the registry is in another key(...\PowerShell\3\PowerShellEngine), but I'm gussing PS3.0 is not necessary to know since it's so new and all PS scripts work with PS 2.0.
Update: Powershell version
function Check-PS { [CmdletBinding()] param ( [Parameter(ValueFromPipeline=$true)] [String[]]$ComputerName = $env:COMPUTERNAME ) Process { foreach ($computer in $ComputerName) { $path = "\\$computer\C$\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" $exists = $false #Check if exists if(Test-Path $path){ $exists = $true #Detect version switch -Wildcard ((Get-ChildItem $path).VersionInfo.ProductVersion) { "6.0*" { $ver = 1 } "6.1*" { $ver = 2 } "6.2*" { $ver = 3 } default { $ver = 0 } } } else { Write-Error "Failed to connect to $computer" $ver = -1 } #Return object New-Object pscustomobject -Property @{ Computer = $computer HasPowerShell = $exists Version = $ver } } }}
It supports mulitple computernames and input via pipeline.
Check-PS -ComputerName "Computer1", "Computer2"
Or
"Computer1", "Computer2" | Check-PS
Test with localcomputer(default computername):
PS > Check-PSHasPowerShell Computer Version------------- -------- ------- True FRODE-PC 3