Darktux
Darktux

Reputation: 427

How to know if powershell is installed on remote workstation?

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?

Upvotes: 7

Views: 22909

Answers (2)

Frode F.
Frode F.

Reputation: 54821

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

Upvotes: 2

Loïc MICHEL
Loïc MICHEL

Reputation: 26120

check if file exist ?

$path= "\\remote\C$\windows\System32\WindowsPowerShell\v1.0\powershell.exe"
if(test-path $path){(ls $path).VersionInfo}

Upvotes: 4

Related Questions