UseCompatibleTypes
심각도 수준: 경고
Description
이 규칙은 대상 PowerShell 플랫폼에서 사용할 수 없는 형식(기본적으로 로드됨)을 식별합니다.
PowerShell 플랫폼은 다음 형식의 이름으로 식별됩니다.
<os-name>_<os-arch>_<os-version>_<ps-version>_<ps-arch>_<dotnet-version>_<dotnet-edition>
위치:
<os-name>
: 운영 체제 PowerShell의 이름이 실행 중입니다. Windows에서는 SKU 번호가 포함됩니다. Linux에서 이 이름은 배포의 이름입니다.<os-arch>
: 운영 체제가 실행 중인 컴퓨터 아키텍처입니다(일반적으로x64
).<os-version>
: 자체 보고된 운영 체제 버전입니다(Linux에서는 배포 버전임).<ps-version>
: PowerShell 버전(에서$PSVersionTable.PSVersion
)입니다.<ps-arch>
: PowerShell 프로세스의 컴퓨터 아키텍처입니다.<dotnet-version>
: 에서 .System.Environment.Version
NET 런타임 PowerShell의 보고된 버전이 실행 중입니다.<dotnet-edition>
: .NET 런타임 버전 PowerShell이 (현재framework
또는core
)에서 실행 중입니다.
예:
win-4_x64_10.0.18312.0_5.1.18312.1000_x64_4.0.30319.42000_framework
는 x64용 Windows 10 Enterprise(빌드 18312)에서 실행되는 PowerShell 5.1입니다.win-4_x64_10.0.18312.0_6.1.2_x64_4.0.30319.42000_core
는 동일한 운영 체제에서 실행되는 PowerShell 6.1.2입니다.ubuntu_x64_18.04_6.2.0_x64_4.0.30319.42000_core
는 Ubuntu 18.04에서 실행되는 PowerShell 6.2.0입니다.
일부 플랫폼은 PSScriptAnalyzer와 함께 JSON 파일로 번들로 제공되며, 구성에서 대상 지정을 위해 이러한 방식으로 명명됩니다.
기본적으로 번들로 제공되는 플랫폼은 다음과 같습니다.
PowerShell 버전 | 운영 체제 | ID |
---|---|---|
3.0 | Windows Server 2012 | win-8_x64_6.2.9200.0_3.0_x64_4.0.30319.42000_framework |
4.0 | Windows Server 2012R2 | win-8_x64_6.3.9600.0_4.0_x64_4.0.30319.42000_framework |
5.1 | Windows Server 2016 | win-8_x64_10.0.14393.0_5.1.14393.2791_x64_4.0.30319.42000_framework |
5.1 | Windows Server 2019 | win-8_x64_10.0.17763.0_5.1.17763.316_x64_4.0.30319.42000_framework |
5.1 | Windows 10 1809(RS5) | win-48_x64_10.0.17763.0_5.1.17763.316_x64_4.0.30319.42000_framework |
6.2 | Windows Server 2016 | win-8_x64_10.0.14393.0_6.2.4_x64_4.0.30319.42000_core |
6.2 | Windows Server 2019 | win-8_x64_10.0.17763.0_6.2.4_x64_4.0.30319.42000_core |
6.2 | Windows 10 1809(RS5) | win-4_x64_10.0.17763.0_6.2.4_x64_4.0.30319.42000_core |
6.2 | Ubuntu 18.04 LTS | ubuntu_x64_18.04_6.2.4_x64_4.0.30319.42000_core |
7.0 | Windows Server 2016 | win-8_x64_10.0.14393.0_7.0.0_x64_3.1.2_core |
7.0 | Windows Server 2019 | win-8_x64_10.0.17763.0_7.0.0_x64_3.1.2_core |
7.0 | Windows 10 1809(RS5) | win-4_x64_10.0.17763.0_6.2.4_x64_3.1.2_core |
7.0 | Ubuntu 18.04 LTS | ubuntu_x64_18.04_7.0.0_x64_3.1.2_core |
다른 프로필은 GitHub 리포지토리에서 찾을 수 있습니다.
PSCompatibilityCollector 모듈을 사용하여 사용자 고유의 플랫폼 프로필을 생성할 수도 있습니다.
호환성 프로필 설정은 아래에서 TargetProfiles
대상으로 지정할 플랫폼 목록을 사용합니다. 플랫폼은 다음과 같이 지정할 수 있습니다.
- 플랫폼 이름(예:
ubuntu_x64_18.04_6.1.1_x64_4.0.30319.42000_core
).json
은 끝에 추가되고 기본 프로필 디렉터리에서 검색됩니다. - 기본 프로필 디렉터리에서 를 검색할 파일 이름(예:
my_custom_platform.json
)입니다. - 파일의 절대 경로입니다(예:
D:\PowerShellProfiles\TargetMachine.json
).
기본 프로필 디렉터리가 의 PSScriptAnalzyer 모듈 $PSScriptRoot/PSCompatibilityCollector/profiles
아래에 있습니다(여기서 는 $PSScriptRoot
가 포함된 PSScriptAnalyzer.psd1
디렉터리를 참조함).
호환성 분석은 대상 프로필과 'union' 프로필 모두에 사용되는 형식을 비교합니다(프로필 dir의 모든 프로필에서 사용할 수 있는 모든 형식 포함). 형식이 공용 구조체 프로필에 없는 경우 로컬로 만들어지고 무시되는 것으로 간주됩니다. 그렇지 않으면 형식이 공용 구조체 프로필에 있지만 대상에 없는 경우 해당 대상과 호환되지 않는 것으로 간주됩니다.
구성 설정
구성 키 | 의미 | 허용되는 값 | 필수 | 예제 |
---|---|---|---|---|
Enable |
규칙을 활성화합니다. | bool($true /$false ) |
아니요(기본값: $false ) |
$true |
TargetProfiles |
대상으로 지정할 PowerShell 프로필 목록 | string[]: 프로필 디렉터리의 프로필 파일 또는 프로필 이름에 대한 절대 경로 | 아니요(기본값: @() ) |
@('ubuntu_x64_18.04_6.1.3_x64_4.0.30319.42000_core', 'win-48_x64_10.0.17763.0_5.1.17763.316_x64_4.0.30319.42000_framework') |
ProfileDirPath |
이름으로 프로필을 검색하고 공용 구조체 프로필 생성에 사용할 위치 | string: 새 프로필 dir에 대한 절대 경로 | 아니요(PSScriptAnalyzer 모듈의 디렉터리 기본값 compatibility_profiles ) |
C:\Users\me\Documents\pssaCompatProfiles |
IgnoreTypes |
스크립트에서 호환성을 무시할 형식 또는 형식 가속기의 전체 이름 | string[]: 무시할 형식의 이름 | 아니요(기본값: @() ) |
@('System.Collections.ArrayList','string') |
예제 구성은 다음과 같을 수 있습니다.
@{
Rules = @{
PSUseCompatibleTypes = @{
Enable = $true
TargetProfiles = @(
'ubuntu_x64_18.04_6.1.3_x64_4.0.30319.42000_core'
'win-48_x64_10.0.17763.0_5.1.17763.316_x64_4.0.30319.42000_framework'
'MyProfile'
'another_custom_profile_in_the_profiles_directory.json'
'D:\My Profiles\profile1.json'
)
# You can specify types to not check like this, which will also ignore methods and members on it:
IgnoreTypes = @(
'System.IO.Compression.ZipFile'
)
}
}
}
또는 다음과 같이 설정 개체를 제공할 수 있습니다.
PS> $settings = @{
Rules = @{
PSUseCompatibleTypes = @{
Enable = $true
TargetProfiles = @('win-48_x64_10.0.17763.0_5.1.17763.316_x64_4.0.30319.42000_framework')
}
}
}
PS> Invoke-ScriptAnalyzer -Settings $settings -ScriptDefinition '[System.Management.Automation.SemanticVersion]'1.18.0-rc1''
RuleName Severity ScriptName Line Message
-------- -------- ---------- ---- -------
PSUseCompatibleTypes Warning 1 The type 'System.Management.Automation.SemanticVersion' is
not available by default in PowerShell version
'5.1.17763.316' on platform 'Microsoft Windows 10 Pro'
표시 안 함
명령 호환성 진단 다른 규칙과 마찬가지로 scriptblock 블록의 특성 param
으로 표시하지 않을 수 있습니다.
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseCompatibleTypes', '')]
규칙은 특정 형식에 대해서만 표시되지 않을 수도 있습니다.
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseCompatibleTypes', 'System.Management.Automation.Security.SystemPolicy')]
또한 형식 멤버에 대해서만 표시되지 않습니다.
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseCompatibleCommands', 'System.Management.Automation.LanguagePrimitives/ConvertTypeNameToPSTypeName')]
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기