다음을 통해 공유


about_PowerShell_Editions

간단한 설명

PowerShell 버전이 서로 다른 기본 런타임에서 실행됩니다.

자세한 설명

PowerShell 5.1에서는 각각 다른 .NET 런타임에서 실행되는 여러 버전의 PowerShell이 있습니다. PowerShell 6.0에는 두 가지 버전의 PowerShell이 있습니다.

  • .NET Framework에서 실행되는 데스크톱입니다. PowerShell 4 이하 및 PowerShell 5.1은 Windows 데스크톱, Windows Server, Windows Server Core 및 대부분의 다른 Windows 운영 체제와 같은 완전한 기능을 갖춘 Windows 버전에 사용할 수 있습니다. 원래 PowerShell 버전이며 운영 체제의 기본 설치에 포함됩니다.
  • .NET Core에서 실행되는 Core입니다. PowerShell 6.0 이상은 이전 PowerShell 릴리스와 함께 전체 기능을 갖춘 Windows 버전, Windows Nano Server 및 Windows IoT와 같은 일부 축소된 Windows 버전 또는 Linux 및 macOS와 같은 비 Windows 플랫폼에 함께 설치됩니다.

PowerShell 버전은 .NET 런타임에 해당하므로 .NET API 및 PowerShell 모듈 호환성의 기본 표시기입니다. 일부 .NET API, 형식 또는 메서드는 .NET 런타임에서 모두 사용할 수 없으며 이는 PowerShell 스크립트 및 이에 의존하는 모듈에 영향을 줍니다.

$PSEdition 자동 변수

PowerShell 5.1 이상에서는 자동 변수를 $PSEdition 사용하여 실행 중인 버전을 확인할 수 있습니다.

$PSEdition
Core

PowerShell 4 이하에서는 이 변수가 없습니다. $PSEdition null인 경우 값 Desktop이 있는 것과 동일하게 처리되어야 합니다.

Edition in $PSVersionTable

$PSVersionTable 자동 변수에는 PowerShell 5.1 이상의 PSEdition 속성도 있습니다.

$PSVersionTable
Name                           Value
----                           -----
PSVersion                      7.2.2
PSEdition                      Core
GitCommitId                    7.2.2
OS                             Microsoft Windows 10.0.22000
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

PSEdition 필드에는 자동 변수와 동일한 값이 $PSEdition 있습니다.

CompatiblePSEditions 모듈 매니페스트 필드

PowerShell 모듈은 모듈 매니페스트 필드를 사용하여 CompatiblePSEditions 호환되는 PowerShell 버전을 선언할 수 있습니다.

예를 들어 PowerShell 버전과 DesktopCore 호환성을 선언하는 모듈 매니페스트:

@{
    ModuleVersion = '1.0'
    FunctionsToExport = @('Test-MyModule')
    CompatiblePSEditions = @('Desktop', 'Core')
}

호환성만 Desktop 있는 모듈 매니페스트의 예:

@{
    ModuleVersion = '1.0'
    FunctionsToExport = @('Test-MyModule')
    CompatiblePSEditions = @('Desktop')
}

모듈 매니페스트에서 필드를 생략 CompatiblePSEditions 하면 이 필드가 도입되기 전에 만든 모듈이 이 버전에 Desktop대해 암시적으로 작성되었기 때문에 모듈 매니페스트에서 필드를 설정하는 것과 동일한 효과가 있습니다.

Windows의 일부로 제공하지 않는 모듈(즉, 갤러리에서 작성하거나 설치하는 모듈)의 경우 이 필드는 정보 전용입니다. PowerShell은 필드에 따라 동작을 CompatiblePSEditions 변경하지 않지만 사용자 고유의 PSModuleInfo 논리에 대해 개체(반환됨)에 Get-Module노출합니다.

New-ModuleManifest -Path .\TestModuleWithEdition.psd1 -CompatiblePSEditions Desktop,Core -PowerShellVersion '5.1'
$ModuleInfo = Test-ModuleManifest -Path .\TestModuleWithEdition.psd1
$ModuleInfo.CompatiblePSEditions
Desktop
Core

참고 항목

CompatiblePSEditions 모듈 필드는 PowerShell 5.1 이상과만 호환됩니다. 이 필드를 포함하면 모듈이 PowerShell 4 이하와 호환되지 않습니다. 필드는 순전히 정보 제공이므로 이후 PowerShell 버전에서 안전하게 생략할 수 있습니다.

PowerShell 6.1 Get-Module -ListAvailable 에서는 각 모듈의 버전 호환성을 표시하도록 포맷터가 업데이트되었습니다.

Get-Module -ListAvailable

    Directory: C:\Users\me\Documents\PowerShell\Modules

ModuleType Version    Name                   PSEdition ExportedCommands
---------- -------    ----                   --------- ----------------
Script     1.4.0      Az                     Core,Desk
Script     1.3.1      Az.Accounts            Core,Desk {Disable-AzDataCollection, Disable-AzContextAutosave, E...
Script     1.0.1      Az.Aks                 Core,Desk {Get-AzAks, New-AzAks, Remove-AzAks, Import-AzAksCreden...

...

Script     4.4.0      Pester                 Desk      {Describe, Context, It, Should...}
Script     1.18.0     PSScriptAnalyzer       Desk      {Get-ScriptAnalyzerRule, Invoke-ScriptAnalyzer, Invoke-...
Script     1.0.0      WindowsCompatibility   Core      {Initialize-WinSession, Add-WinFunction, Invoke-WinComm...

Windows의 일부로 제공되는 모듈에 대한 버전 호환성

Windows의 일부로 제공되는 모듈(또는 역할 또는 기능의 일부로 설치됨)의 경우 PowerShell 6.1 이상에서는 필드를 다르게 처리 CompatiblePSEditions 합니다. 이러한 모듈은 Windows PowerShell 시스템 모듈 디렉터리(%windir%\System\WindowsPowerShell\v1.0\Modules)에서 찾을 수 있습니다.

이 디렉터리에서 로드되거나 이 디렉터리에 있는 모듈의 경우 PowerShell 6.1 이상에서는 이 필드를 사용하여 CompatiblePSEditions 모듈이 현재 세션과 호환되고 그에 따라 동작하는지 여부를 결정합니다.

사용되면 Import-Module in CompatiblePSEditions 이 없는 Core 모듈을 가져오지 않고 오류가 표시됩니다.

Import-Module BitsTransfer
Import-Module : Module 'C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\BitsTransfer\BitsTransfer.psd1'
 does not support current PowerShell edition 'Core'. Its supported editions are 'Desktop'. Use 'Import-Module
 -SkipEditionCheck' to ignore the compatibility of this module.
At line:1 char:1
+ Import-Module BitsTransfer
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : ResourceUnavailable: (C:\WINDOWS\system32\u2026r\BitsTransfer.psd1:String)
 [Import-Module], InvalidOperationException
+ FullyQualifiedErrorId : Modules_PSEditionNotSupported,Microsoft.PowerShell.Commands.ImportModuleCommand

사용되는 경우 Get-Module -ListAvailable in CompatiblePSEditions 이 없는 Core 모듈은 표시되지 않습니다.

Get-Module -ListAvailable BitsTransfer
# No output

두 경우 모두 switch 매개 변수를 -SkipEditionCheck 사용하여 이 동작을 재정의할 수 있습니다.

Get-Module -ListAvailable -SkipEditionCheck BitsTransfer

    Directory: C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules

ModuleType Version    Name           PSEdition ExportedCommands
---------- -------    ----           --------- ----------------
Manifest   2.0.0.0    BitsTransfer   Desk      {Add-BitsFile, Complete-BitsTransfer, Get-BitsTransfer,...

Warning

Import-Module -SkipEditionCheck 모듈에 성공하는 것처럼 보일 수 있지만 해당 모듈을 사용하면 나중에 비호환성이 발생할 위험이 있습니다. 모듈을 처음 로드하는 동안 명령이 나중에 호환되지 않는 API를 호출하고 자발적으로 실패할 수 있습니다.

버전 간 호환성을 위한 PowerShell 모듈 작성

PowerShell과 PowerShell 버전을 모두 DesktopCore 대상으로 하는 PowerShell 모듈을 작성할 때 버전 간 호환성을 보장하기 위해 수행할 수 있는 작업이 있습니다.

그러나 호환성을 확인하고 지속적으로 유효성을 검사하는 유일한 방법은 스크립트 또는 모듈에 대한 테스트를 작성하고 호환성이 필요한 모든 버전의 PowerShell에서 실행하는 것입니다. 이를 위해 권장되는 테스트 프레임워크는 Pester입니다.

PowerShell 스크립트

언어로 PowerShell은 버전 간에 동일하게 작동합니다. 버전 호환성의 영향을 받는 cmdlet, 모듈 및 .NET API입니다.

일반적으로 PowerShell 6.1 이상에서 작동하는 스크립트는 Windows PowerShell 5.1에서 작동하지만 몇 가지 예외가 있습니다.

PSScriptAnalyzer 버전 1.18 이상에는 PowerShell 스크립트에서 호환되지 않는 명령 및 .NET API 사용을 검색할 수 있는 PSUseCompatibleCommands 및 PSUseCompatibleTypes와 같은 규칙이 있습니다.

.NET 어셈블리

소스 코드에서 생성된 .NET 어셈블리(DLL)를 통합하는 이진 모듈 또는 모듈을 작성하는 경우 .NET 및 PowerShell API 호환성의 컴파일 시간 호환성 유효성 검사를 위해 .NET Standard 및 PowerShell Standard에 대해 컴파일해야 합니다.

이러한 라이브러리는 컴파일 시간에 일부 호환성을 검사 수 있지만 버전 간에 가능한 동작 차이를 파악할 수는 없습니다. 이를 위해 테스트를 계속 작성해야 합니다.

참고 항목