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
$host.version
is just plain wrong/unreliable. This gives you the version of the hosting executable (powershell.exe, powergui.exe, powershell_ise.exe, powershellplus.exe etc) and not the version of the engine itself.The engine version is contained in
$psversiontable.psversion
. For PowerShell 1.0, this variable does not exist, so obviously if this variable is not available it is entirely safe to assume the engine is 1.0, obviously.get powershell version by
$host.Version
command.output:
I found the easiest way to check if installed was to:
cmd
, then OK)powershell
then hit return. You should then get the PowerShellPS
prompt:You can then check the version from the PowerShell prompt by typing
$PSVersionTable.PSVersion
:Type
exit
if you want to go back to the command prompt (exit
again if you want to also close the command prompt).To run scripts, see http://ss64.com/ps/syntax-run.html.
You can look at the built in variable,
$psversiontable
. If it doesn't exist, you have V1. If it does exist, it will give you all the info you need.I needed to check the version of PS and then run the appropriate code. Some of our servers run v5, others v4. This means that some functions, like compress, may or may not be available.
This is my solution: