How to know if powershell is installed on remote workstation; we need to do the inventory of all the powershell enabled workstations so that we can plan a change for deploying; is there a way to remotely know if powershell is installed and what version?
How to know if powershell is installed on remote workstation?
Asked Answered
what OS are you running on the clients? xp? vista? Windows7 has powershell 2.0 installed by default. –
Ane
Got interested in having a function like this myself, so I updated my answer with a new powershell-version if you need it. :-) –
Ane
check if file exist ?
$path= "\\remote\C$\windows\System32\WindowsPowerShell\v1.0\powershell.exe"
if(test-path $path){(ls $path).VersionInfo}
If i am checking for wither powershell 2.0 or 3.0 , the path should be $path= "\\remote\C$\windows\System32\WindowsPowerShell\v2.0\powershell.exe" or $path= "\\remote\C$\windows\System32\WindowsPowerShell\v3.0\powershell.exe" ? –
Maharani
no. microsoft forgot to change the number, so all versions reside in the v1.0 folder –
Ane
This is my output Product Version is 6.2.8370.0 and FileVersion is 6.2.8370.0 (winmain_win8rc.120428-1335) how to determine if its version 2.0 or 3.0 or even 1.0? –
Maharani
6.0*
is PS1.0, 6.1*
is PS2.0 and 6.2*
is PS3 –
Ane @Graimer - on Server 2008 with PS v2, I'm seeing exe ProductVersion 6.0.6002.18111 –
Keek
Hmm, weird. On
c:\windows\system32\windowspowershell\v1.0\powershell.exe
? I must admit I didn't test it on vista/2008, only 7, 2008r2(ps2.0 is default) and 8/2012. –
Ane 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 off
FOR /F "tokens=3" %%A IN ('REG QUERY "HKLM\SOFTWARE\Microsoft\PowerShell\1" /v Install ^| FIND "Install"') DO SET PowerShellInstalled=%%A
IF NOT "%PowerShellInstalled%"=="0x1" (
echo false > \\remote\location\%COMPUTERNAME%.txt
GOTO end
)
FOR /F "tokens=3" %%A IN ('REG QUERY "HKLM\SOFTWARE\Microsoft\PowerShell\1\PowerShellEngine" /v PowerShellVersion ^| FIND "PowerShellVersion"') DO SET PowerShellVersion=%%A
echo %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-PS
HasPowerShell Computer Version
------------- -------- -------
True FRODE-PC 3
Thanks for the script, one of our domains is using exclusively XP workstations dated back to 2004 , so need to know powershell enabled ones. –
Maharani
© 2022 - 2024 — McMap. All rights reserved.