이 글에서는 PowerShell의 버전 종류, Windows PowerShell과 PowerShell Core의 차이점, 그리고 로컬 또는 원격 컴퓨터에 설치된 PowerShell 버전을 확인하는 방법을 자세히 알아보겠습니다.
Windows PowerShell과 PowerShell Core의 역사 및 버전
PowerShell은 Windows 7 SP1과 Windows Server 2008 R2 SP1부터 시작되는 모든 Windows 버전에 기본적으로 설치되어 있습니다. 아래 표는 지금까지 출시된 모든 PowerShell 버전을 정리한 것입니다.
| PS 버전 | 비고 |
| PowerShell 1.0 | Windows Server 2003 SP1 및 Windows XP에 수동 설치 가능 |
| PowerShell 2.0 | Windows Server 2008 R2 및 Windows 7에 탑재 |
| PowerShell 3.0 | Windows 8 및 Windows Server 2012에 탑재 |
| PowerShell 4.0 | Windows 8.1 및 Windows Server 2012 R2에 탑재 |
| PowerShell 5.0 | Windows 10 RTM에 사전 설치되며, Windows Update를 통해 5.1로 자동 업데이트 |
| PowerShell 5.1 | Windows 10 (빌드 1709 이상) 및 Windows Server 2016에 기본 탑재 |
| PowerShell Core 6.0 및 6.1 | .NET Core 기반의 차세대 크로스 플랫폼 PowerShell 버전으로, 지원되는 모든 Windows 버전은 물론 macOS, CentOS, RHEL, Debian, Ubuntu, openSUSE에도 설치 가능 |
| PowerShell Core 7.0 | 2020년 3월에 출시된 최신 PowerShell 버전 (.NET Core 2.x 대신 .NET Core 3.1 사용) |
이전 버전의 Windows에서도 최신 PowerShell 버전을 수동으로 설치할 수 있습니다. 이를 위해서는 Windows Management Framework(PowerShell이 포함되어 있음)의 해당 버전을 다운로드하여 설치하면 됩니다.
참고로 최근 2년간 Microsoft는 기존 Windows PowerShell의 개발을 중단하고(버그 수정 및 보안 업데이트만 제공) 오픈소스 크로스 플랫폼인 PowerShell Core에 개발 역량을 집중하고 있습니다.
Windows PowerShell과 PowerShell Core의 차이점은 무엇인가?
- Windows PowerShell은 .NET Framework 기반입니다(예: PowerShell 5는 .NET Framework v4.5 필요). 반면 PowerShell Core는 .NET Core 기반입니다.
- Windows PowerShell은 Windows 운영체제에서만 작동하지만, PowerShell Core는 크로스 플랫폼으로 Linux에서도 사용할 수 있습니다.
- PowerShell Core는 Windows PowerShell과 100% 호환되지는 않지만, Microsoft는 기존 PS cmdlet 및 스크립트와의 하위 호환성 개선을 지속적으로 진행 중입니다. (기존 PS1 스크립트를 PowerShell Core로 이전하기 전에 테스트하는 것이 좋습니다.) PowerShell Core 7은 Windows PowerShell과의 호환성이 가장 높습니다.
- PowerShell ISE 편집기로는 PowerShell Core 스크립트를 편집할 수 없습니다(대신 Visual Studio Code 사용 가능).
- Windows PowerShell은 더 이상 개발되지 않으므로, PowerShell Core로의 전환을 시작하는 것이 좋습니다.
콘솔에서 PowerShell 버전 확인하는 방법
컴퓨터에 설치된 PowerShell 버전을 확인하는 가장 간단한 방법은 다음 명령어를 사용하는 것입니다.
host
출력 결과에서 Version 속성 값을 확인하면 됩니다. 아래 스크린샷은 Windows Server 2016과 마찬가지로 PowerShell 5.1이 기본 설치된 Windows 10에서 촬영한 것입니다.
또는 다음 명령어를 사용할 수도 있습니다.
$PSVersionTable
PowerShell 버전 값만 따로 확인하고 싶다면 아래와 같이 입력합니다.
$PSVersionTable.PSVersion.major
(아래 예시는 초기 상태의 Windows Server 2008 R2에서 PSVersion 2.0을 확인한 결과입니다.)
$PSVersionTable 명령은 서로 다른 운영체제의 PowerShell Core에서도 정확하게 작동합니다.
레지스트리를 통해서도 설치된 PowerShell 버전을 확인할 수 있습니다. Get-ItemProperty cmdlet을 사용하여 레지스트리 키 HKLM\SOFTWARE\Microsoft\PowerShell\3\PowerShellEngine의 PowerShellVersion 매개변수 값을 가져오면 됩니다.
(Get-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\PowerShell\3\PowerShellEngine -Name 'PowerShellVersion').PowerShellVersion
위 방법은 Windows Server 2012/Windows 8 이상에서 작동합니다.
Windows Server 2008 R2/Windows 7에서는 다른 레지스트리 키의 매개변수 값을 확인해야 합니다.
(Get-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\PowerShell\1\PowerShellEngine -Name 'PowerShellVersion').PowerShellVersion
설치된 PowerShell Core의 버전을 확인하려면 다음 명령어를 사용합니다.
(Get-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\PowerShellCore\InstalledVersions* -Name 'SemanticVersion').SemanticVersion
원격 컴퓨터의 PowerShell 버전 확인하기
원격 호스트의 PowerShell 버전을 확인하려면 $PSVersionTable 환경 변수 값을 사용하거나 레지스트리에서 직접 정보를 가져와야 합니다. 다른 방법은 잘못된 데이터를 반환할 수 있습니다.
Invoke-Command cmdlet을 사용하여 PowerShell Remoting을 통해 원격 컴퓨터에 설치된 PowerShell 버전을 확인할 수 있습니다.
Invoke-Command -ComputerName mun-dc01 -ScriptBlock {$PSVersionTable.PSVersion} -Credential $cred
Major Minor Build Revision PSComputerName
----- ----- ----- -------- --------------
5 1 14393 3383 mun-dc01
다음 스크립트를 사용하면 여러 대의 컴퓨터에 설치된 PowerShell 버전을 한 번에 확인할 수 있습니다(원격 컴퓨터 목록은 일반 텍스트 파일로 지정).
Invoke-Command -ComputerName (Get-Content C:\PS\host_list.txt) -ScriptBlock{$PSVersionTable.PSVersion} | Select PSComputerName, @{N="PS Version";E={$_.Major}}
또는 Get-ADComputer로 도메인 컴퓨터 목록을 가져온 후, 해당 컴퓨터들의 PowerShell 버전을 원격으로 확인할 수도 있습니다.
$adcomputer=(Get-ADComputer -Filter 'operatingsystem -like "*Windows server*" -and enabled -eq "true"' -SearchBase 'OU=servers,OU=Munich,dc=woshub,dc=com').Name
Invoke-Command -ComputerName $adcomputer -Scriptblock{$PSVersionTable.psversion} -ErrorAction SilentlyContinue
PowerShell 스크립트가 특정 PS 버전의 기능을 사용하는 경우, 스크립트가 다른 PowerShell 버전으로 실행되도록 강제할 수 있습니다. 예를 들어 PowerShell v3 모드로 콘솔을 실행하려면 다음 명령어를 사용합니다(.NET Framework 3.5가 설치되어 있어야 함).
PowerShell.exe -version 3
특정 PS 버전의 cmdlet이나 기능을 사용하는 스크립트나 명령을 실행할 때는 자신의 PowerShell 버전을 아는 것이 중요합니다. 스크립트 내에서 설치된 PowerShell 버전을 감지하고 이에 따라 cmdlet을 분기 처리하려면 다음 PS 스크립트를 활용할 수 있습니다.
$ps_version = $PSVersionTable.PSVersion.major
if ( $ps_version -eq "2" )
{
write "You are using Powershell 2.0"
}
elseif ( $ps_version -eq "5" )
{
write " You are using Powershell 5"
}
다음 글에서는 Windows에서 PowerShell 버전을 업데이트하는 방법을 살펴보겠습니다.