I’ve been tossing around some ideas on how to check the version of PowerShell remotely. I need to code for the following situations:
- PowerShell Not Installed (Pre-my employment)
- PowerShell v1-v2 - HKLM\Software\Microsoft\PowerShell\1\PowerShellEngine\PowerShellVersion (ex: v2.0)
- PowerShell v3-v4 (5?) - HKLM\Software\Microsoft\PowerShell\3\PowerShellEngine\PowerShellVersion (ex: v4.0
In terms of my Psuedo code, I’m going to open my registry connection, attempt to connect to the Key with 3 in it. If it does exist, get the PowerShellVersion value.
If my Try/Catch fails, then try to connect to the Key with 1 in it. If that fails, then assume PowerShell is not installed.
Is there anything I’m missing, or is there a better way to do this? I don’t want to rely on WinRM at this point, as we’re trying to find out where PS is not installed, so we can remediate.