항목
about_Requires
간단한 설명
지정된 스냅인과 버전을 요구하여 스크립트의 실행을 방지합니다.
자세한 설명
#Requires 문은 Windows PowerShell 버전, 스냅인 및 스냅인 버전 전제 조건이 충족되지 않는 경우
스크립트가 실행되지 못하게 합니다. 전제 조건이 충족되지 않으면 Windows PowerShell에서
스크립트를 실행하지 않습니다.
#Requires 문은 모든 스크립트에서 사용할 수 있지만 함수, cmdlet 또는 스냅인에서는 사용할 수 없습니다.
구문
다음 구문을 사용하여 요구할 스냅인과 스냅인 버전을 지정합니다.
#requires -PsSnapIn <PsSnapIn> [-Version <N>[.<n>]]
다음 구문을 사용하여 요구할 Windows PowerShell의 최소 버전을 지정합니다.
#requires -Version <N>[.<n>]
다음 구문을 사용하여 요구할 셸을 지정합니다.
#requires -ShellId <ShellId>
사용 규칙
- #Requires 문은 스크립트의 줄에서 첫 번째 항목이어야 합니다.
- 스크립트에는 #Requires 문이 두 개 이상 포함될 수 있습니다.
- #Requires 문은 스크립트에 있는 임의의 줄에 나타날 수 있습니다.
예
다음 문은 Microsoft.PowerShell.Security 스냅인을 요구합니다.
#requires -PsSnapIn Microsoft.PowerShell.Security
Microsoft.PowerShell.Security 스냅인이 로드되지 않는 경우 스크립트가 실행되지 않고 Windows
PowerShell에서 다음과 같은 오류 메시지를 표시합니다.
"'<script-name>' 스크립트의 "#requires" 문에 지정된 Microsoft.PowerShell.Security 스냅인이
없으므로 해당 스크립트를 실행할 수 없습니다."
다음 문은 Windows PowerShell 2.0 버전이나 Microsoft.PowerShell.Security 스냅인의 이후
버전을 요구합니다.
#requires -PsSnapIn Microsoft.PowerShell.Security -Version 2
다음 문은 Windows PowerShell 2.0 이상 버전을 요구합니다.
#requires -Version 2.0
다음 스크립트에는 #Requires 문이 두 개 있습니다. 두 문에 지정된 요구 사항이 충족되어야 하며,
충족되지 않으면 스크립트가 실행되지 않습니다. 각 #Requires 문은 줄의 첫 번째 항목이어야
합니다.
#requires –PsSnapIn Microsoft.PowerShell.Security –Version 2
Get-WMIObject WIN32_LogicalDisk | out-file K:\status\DiskStatus.txt
#requires –Version 2
다음 #Requires 문은 지정된 셸 ID가 현재 셸 ID와 일치하지 않으면 스크립트가 실행되지 못하게 합니다.
현재 셸 ID는 $ShellId 변수에 저장되어 있습니다.
#requires -ShellId MyLocalShell
참고 항목
about_Automatic_Variables
about_Language_Keywords
about_PSSnapins
get-PSSnapin