Determine installed PowerShell version

前端 未结 19 2621
半阙折子戏
半阙折子戏 2020-11-22 09:40

How can I determine what version of PowerShell is installed on a computer, and indeed if it is installed at all?

19条回答
  •  爱一瞬间的悲伤
    2020-11-22 10:07

    I needed to check the version of PowerShell and then run the appropriate code. Some of our servers run v5, and others v4. This means that some functions, like compress, may or may not be available.

    This is my solution:

    if ($PSVersionTable.PSVersion.Major -eq 5) {
        #Execute code available in PowerShell 5, like Compress
        Write-Host "You are running PowerShell version 5"
    }
    else {
        #Use a different process
        Write-Host "This is version $PSVersionTable.PSVersion.Major"
    }
    

提交回复
热议问题