How can I determine what version of PowerShell is installed on a computer, and indeed if it is installed at all?
标签:
powershell
相关问题
- How to Debug/Register a Permanent WMI Event Which
- How can I do variable substitution in a here-strin
- How to use a default value with parameter sets in
- Does powershell have a method_missing()?
- Invoking Mirth Connect CLI with Powershell script
相关文章
- 在vscode如何用code runner打开独立的控制台窗口,以及设置好调试模式时窗口的编码?
- C#调用PowerShell的问题
- EscapeDataString having differing behaviour betwee
- PowerShell Change owner of files and folders
- Command line escaping single quote for PowerShell
- Is there a simple way to pass specific *named* Pow
- How do I access an element with xpath with a names
- How to 'Grant Permissions' Using Azure Act
I would use either Get-Host or $PSVersionTable. As Andy Schneider points out,
$PSVersionTable
doesn't work in version 1; it was introduced in version 2.The below cmdlet will return the PowerShell version.
Microsoft's recommended forward compatible method for checking if PowerShell is installed and determining the installed version is to look at two specific registry keys. I've reproduced the details here in case the link breaks.
According to the linked page:
To check if any version of PowerShell is installed, check for the following value in the registry:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1
To check whether version 1.0 or 2.0 of PowerShell is installed, check for the following value in the registry:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\PowerShellEngine
Use Get-Host to get the details for the PowerShell version:
You can verify that Windows PowerShell version installed by completing the following check:
In the Windows PowerShell console, type the following command at the command prompt and then press ENTER:
Get-Host | Select-Object Version
You will see output that looks like this:
http://www.myerrorsandmysolutions.com/how-to-verify-the-windows-powershell-version-installed/
Since the most helpful answer didn't address the if exists portion, I thought I'd give one take on it via a quick-and-dirty solution. It relies on PowerShell being in the path environment variable which is likely what you want. (Hat tip to the top answer as I didn't know that.) Paste this into a text file and name it
or similar.