Computer >> 컴퓨터 >  >> 체계 >> Windows Server

Windows에서 PowerShell 버전 업데이트

이 문서에서는 Windows PowerShell을 업데이트하는 방법을 보여줍니다. 최신 5.1로 버전 및 설치(업그레이드) PowerShell Core 7.1. 이전 기사에서 우리는 현재 두 가지 버전의 PowerShell이 ​​있다고 말했습니다. 클래식 Windows PowerShell (최신 버전은 5.1이며 더 이상 개발되지 않음) 및 새로운 PowerShell Core 플랫폼(현재 버전 7.1 사용 가능). PowerShell 버전 번호는 5.1(6.0, 6.1, 7.0, 7.1 등)부터 계속되지만 두 플랫폼은 다릅니다. 따라서 Windows PowerShell과 PowerShell Core를 모두 업데이트하는 방법을 보여 드리겠습니다.

내용:

  • Windows PowerShell 5.1로 업그레이드
  • PowerShell Core 7을 설치하거나 업데이트하는 방법
  • Microsoft Store를 통해 PowerShell Core 설치
  • 그룹 정책으로 PowerShell Core 배포
  • 원격으로 PowerShell 업데이트

Windows PowerShell 5.1로 업그레이드

PowerShell 4.0은 기본적으로 Windows Server 2012 R2(Windows 8.1)에 설치됩니다. Windows Server 2012 R2에서 Windows PowerShell 버전을 5.1로 업데이트해 보겠습니다.

우선, 현재 PowerShell 버전을 확인하십시오(스크린샷은 PowerShell 4.0이 설치된 것을 보여줍니다):

$PSVersionTable.PSVersion

Windows에서 PowerShell 버전 업데이트

PowerShell 버전을 5.1로 업그레이드하려면 Windows Management Framework 5.1을 설치하세요. , .NET Framework 4.5.2 필요 (또는 최신). 다음 명령을 사용하여 .NET 4.5.2 이상이 설치되어 있는지 확인하십시오.

(Get-ItemProperty ‘HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full’ -Name Release).Release

Windows에서 PowerShell 버전 업데이트

제 경우에는 릴리스 버전 378675 .NET Framework 버전 4.5.1이 설치되어 있음을 의미합니다. 따라서 최신 .NET Framework 4.8을 다운로드하여 설치해야 합니다(오프라인 설치 프로그램에 대한 링크는 다음과 같습니다. https://go.microsoft.com/fwlink/?linkid=2088631 — ndp48-x86-x64-allos-enu.exe ).

.NET 4.8을 설치합니다(컴퓨터를 재부팅해야 함):

Windows에서 PowerShell 버전 업데이트

.NET 4.5.2 없이 WMF 5.1을 설치하면 일부 PowerShell 기능을 사용할 수 없습니다.

WMF 5.1 다운로드 Windows Server 2012 R2용 — Win8.1AndW2K12R2-KB3191564-x64.msu (https://go.microsoft.com/fwlink/?linkid=839516).

Windows Management Framework 5.1 MSU 파일을 설치합니다.

Windows에서 PowerShell 버전 업데이트

서버를 다시 시작한 후 PS 콘솔을 열고 PowerShell 버전이 5.1로 업데이트되었는지 확인합니다.

Windows에서 PowerShell 버전 업데이트

지원되지 않는 Windows 7 또는 Windows Server 2008 R2가 있는 경우 동일한 방법으로 PowerShell 버전을 2.0에서 5.1로 업그레이드할 수 있습니다. 먼저 .Net Framework 4.5.2를 설치합니다. (또는 그 이상), WMF 5.1 (다운로드 링크는 Windows Server 2012 R2용 링크와 다릅니다).

PowerShell Core 7을 설치하거나 업데이트하는 방법

Windows 10 및 Windows Server 2019에 설치된 최신 Windows PowerShell 버전은 PowerShell 5.1입니다. Microsoft는 대신 크로스 플랫폼 PowerShell Core 버전을 개발하기 시작했습니다. 현재 PowerShell Core 6.0, 6.1, 6.2, 7.0 및 7.1을 사용할 수 있습니다. PowerShell 코어 본질적으로 Windows PowerShell과 함께 컴퓨터에 설치되는 새로운 플랫폼입니다. 이는 PowerShell 5.1을 PowerShell Core 7.1로 업그레이드할 수 없음을 의미합니다. PowerShell 7은 Windows PowerShell 5.1과 별도로 컴퓨터에 설치됩니다.

PowerShell 7.1에서 개발자는 Windows PowerShell과의 최대 호환성을 추가했습니다. 따라서 PowerShell Core에서 이전 PS1 스크립트 및 cmdlet을 쉽게 실행할 수 있습니다.

PowerShell Core 6.0이 설치된 경우 컴퓨터의 PowerShell 버전을 최신 PowerShell 7.1 Core로 업데이트할 수 있습니다(또는 Windows PowerShell 5.1과 함께 PowerShell Core 7.1을 설치할 수 있음). 이 예에서는 Windows 10 20H2에서 PowerShell Core를 업데이트하려고 합니다. 두 가지 방법으로 업그레이드할 수 있습니다.

  • GitHub에서 PowerShell Core MSI 설치 프로그램을 수동으로 다운로드할 수 있습니다.
  • PowerShell 콘솔에서 직접 다운로드 및 설치(업데이트)할 수 있습니다.
PowerShell Core의 최신 릴리스는 Windows 7 SP1, Server 2008 R2 이상부터 모든 Windows 버전에 설치할 수 있습니다.

MSI 패키지를 사용하여 PowerShell Core를 설치하려면 프로젝트 페이지 https://github.com/PowerShell/PowerShell로 이동하여 최신 안정 릴리스를 찾으십시오. 이 글을 쓰는 시점은 PowerShell v7.1.3의 2021년 3월 4일 릴리스입니다. . PowerShell v7.2.0의 더 높은 미리 보기 릴리스도 사용할 수 있지만 더 안정적인 버전을 기다리는 것이 좋습니다. 자산 확장 Windows 버전(PowerShell-7.1.3-win-x64.msi 또는 PowerShell-7.1.3-win-x86.msi ).

Windows에서 PowerShell 버전 업데이트

MSI 파일을 다운받아 설치하세요.

Windows에서 PowerShell 버전 업데이트

자동 모드에서 SCCM/MDT/scripts를 사용하여 MSI 패키지에서 PowerShell Core를 설치하려면 다음 매개변수와 함께 명령을 사용할 수 있습니다.

msiexec.exe /package PowerShell-7.1.0-win-x86.msi /quiet ADD_EXPLORER_CONTEXT_MENU_OPENPOWERSHELL=1 ENABLE_PSREMOTING=1 REGISTER_MANIFEST=1

PS cli에서 바로 PowerShell을 업데이트할 수 있습니다.

다음 명령을 사용하여 최신 PowerShell Core 버전을 업데이트(설치)해 보겠습니다.

iex "& { $(irm https://aka.ms/install-powershell.ps1) } -UseMSI"

이 명령은 GitHub에서 PowerShell 7.1 MSI 배포 파일을 다운로드한 다음 MSI 설치 프로그램을 통해 설치를 시작합니다.

다른 설치 매개변수를 사용할 수도 있습니다.

  • -목적지 – 기본 PowerShell Core 설치 폴더 변경
  • -미리보기 – 최신 Preview PowerShell 버전 설치
  • -조용함 – 조용한 설치 모드
  • -AddToPath – 환경 변수에 PowerShell Core 설치 디렉터리 경로를 추가합니다.

Windows에서 PowerShell 버전 업데이트

설치가 완료되면 PowerShell Core(pwsh.exe) 창이 나타납니다. 여기에서 PowerShell 버전을 확인하여 PoSh 7.1.3인지 확인하십시오.

Windows에서 PowerShell 버전 업데이트

WinGet 패키지 관리자가 설치된 경우 PowerShell 버전을 최신 명령으로 설치하거나 업데이트할 수 있습니다.

winget install --id=Microsoft.PowerShell -e

또는 특정 버전의 PowerShell Core를 설치할 수 있습니다.

winget install --id=Microsoft.PowerShell -v "7.1.2" -e

Chocolatey 패키지 관리자가 설치되어 있으면 다음 명령을 사용하세요.

choco install powershell -y
choco upgrade powershell -y

또는 PowerShell 7.x의 경우:
choco install pwsh -y
choco install pwsh -y

다양한 PowerShell 버전의 디렉터리에 주의하십시오.

  • Windows PowerShell 5.1:$env:WINDIR\System32\WindowsPowerShell\v1.0
  • PowerShell 코어 6.x:$env:ProgramFiles\PowerShell\6
  • PowerShell 코어 7.x:$env:ProgramFiles\PowerShell\7

PowerShell 6.x가 컴퓨터에 설치된 경우 $env:ProgramFiles\PowerShell\6 PowerShell 7.1을 설치하면 디렉터리가 자동으로 제거됩니다.

PowerShell 실행 파일의 이름이 변경되었습니다. PowerShell Core에서는 c:\Program Files\PowerShell\7\pwsh.exe입니다. . 시작 메뉴에 자체 아이콘이 있습니다.

  • .NET Framework 기반 Windows PowerShell을 실행하려면 powershell.exe 명령 사용
  • .NET Core 기반 PowerShell Core를 실행하려면 pwsh.exe

Windows에서 PowerShell 버전 업데이트

즉, 컴퓨터에 Windows PowerShell 5.1과 PowerShell Core 7.1이 모두 설치되어 있습니다.

Windows에서 PowerShell 버전 업데이트

장치에 설치된 PowerShell의 버전과 빌드를 확인하려면 pwsh.exe 파일의 버전을 확인할 수 있습니다.

(Get-Command 'C:\Program Files\PowerShell\7\pwsh.exe').Version

Windows에서 PowerShell 버전 업데이트

원격 컴퓨터에 있는 파일의 버전을 확인하는 방법은 다음과 같습니다.

Invoke-Command -Computername computer1 -Scriptblock {(Get-Command 'C:\Program Files\PowerShell\7\pwsh.exe').Version}

Windows PowerShell은 최신 버전이 설치되어 있어도 이전 버전의 PowerShell을 실행할 수 있는 특별한 이전 버전과의 호환성 모드를 제공합니다. 다음 명령을 사용하여 특정 버전(예:4.0)의 PowerShell을 시작할 수 있습니다.

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Version 4

Microsoft Store를 통해 PowerShell Core 설치

Windows 10에서는 Microsoft Store를 통해 PowerShell을 설치하거나 업데이트할 수 있습니다. 스토어에서 PowerShell 앱을 수동으로 찾거나 이 링크를 사용할 수 있습니다. 이 설치 방법의 장점은 Store 앱이 설치된 PowerShell 버전을 추적하고 사용 가능한 경우 앱 업데이트를 자동으로 설치한다는 것입니다.

그러나 이러한 PowerShell 인스턴스가 샌드박스에서 실행된다는 사실에도 단점이 있습니다.

Windows에서 PowerShell 버전 업데이트

APPX/MSIX 응용 프로그램 파일을 다운로드하고 Add-AppxPackage를 사용하여 설치할 수 있습니다. cmdlet(또는 "Microsoft Store 복구" 문서에 설명된 대로).

그룹 정책으로 PowerShell Core 배포

Active Directory 도메인에서 그룹 정책을 사용하여 PowerShell Core를 중앙에서 배포하고 업데이트할 수 있습니다. GPO의 기능을 사용하여 MSI 패키지를 설치합니다.

  1. PowerShell MSI 설치 파일을 다운로드하여 도메인 컨트롤러의 SYSVOL 디렉터리에 복사합니다.
  2. 도메인 그룹 정책 관리 콘솔(gpmc.msc ), 새 GPO를 만들고 컴퓨터 및 서버가 있는 OU에 연결합니다.
  3. GPO 섹션 컴퓨터 구성으로 이동 -> 소프트웨어 설정 , 새 패키지를 만들고 도메인의 SYSVOL 폴더에 PowerShell MSI 설치 파일의 경로를 지정합니다(UNC 경로 사용). Windows에서 PowerShell 버전 업데이트 GPO WMI 필터를 사용하여 정책을 도메인 장치에 보다 정확하게 타겟팅할 수 있습니다.
  4. 소프트웨어 설치 그룹 정책 설정을 업데이트하려면 컴퓨터를 다시 시작해야 합니다. 새 버전의 PowerShell은 시작 시 모든 컴퓨터에 설치됩니다.

원격으로 PowerShell 업데이트

다음 방법 중 하나를 사용하여 명령 프롬프트를 통해 원격 컴퓨터에서 PowerShell을 업데이트할 수 있습니다.

첫 번째 방법을 사용하면 공유 네트워크 폴더에서 MSI 설치 프로그램을 사용하여 컴퓨터에서 PowerShell을 원격으로 업데이트할 수 있습니다.

Invoke-Command -ComputerName mun-srv01 -ScriptBlock {Start-Process msiexec.exe -ArgumentList '/package "\\mun-fs01\install\PowerShell-7.1.3-win-x64.msi" /quiet ADD_EXPLORER_CONTEXT_MENU_OPENPOWERSHELL=1 ENABLE_PSREMOTING=1 REGISTER_MANIFEST=1' -Wait}

다음 스크립트는 Active Directory 도메인에서 모든 활성 Windows 10 컴퓨터를 선택하고 각 컴퓨터에 PowerShell Core 다운로드 및 설치를 시작합니다.

GetADComputer cmdlet을 사용하려면 장치에 Active Directory PowerShell 모듈이 설치되어 있어야 합니다.
$ADComputers = Get-ADComputer -Filter 'operatingsystem -like "*Windows 10*" -and enabled -eq "true"'
ForEach ($computer in $ADcomputers) {
Invoke-Command -ComputerName $computer {iex "& { $(irm https://aka.ms/install-powershell.ps1) } -UseMSI -Quiet"}
}

원격 컴퓨터에 연결할 때 PowerShell Remoting 명령을 사용할 때 주의하십시오(Enter-PSSessionInvoke-Command cmdlet). PowerShell 7.1 끝점에 연결해야 하는 경우 다음 명령을 사용해야 합니다.

Enter-PSSession -ComputerName dc01 -ConfigurationName "powershell.7.1.3"

그렇지 않으면 PowerShell Remoting 5.1 끝점에 연결됩니다.