일반적으로 스위치 매개변수입니다 사양명세 지연합니다 매핑하려는 경우 일부 가변으로 표현식에서는 스위치에서만 매개변수에서 함께 전달할 수 있습니다) 를 알 수 있듯이 웨티프 매개변수입니다.
test.ps1
param ( [string] $source, [string] $dest, [switch] $test )
Copy-Item -Path $source -Destination $dest -WhatIf:$test
이 스위치를 사용하여 작업할 때 뛰어난 유연성을 있습니다. 그러나 이 같은 일이 최대 cmd. exe 또는 뭔가를 전화하시기 powershell 함께 전날에약혼자에게 바람.
D:\test>powershell -file test.ps1 -source test.ps1 -dest test.copy.ps1 -test:$true
D:\test\test.ps1 : Cannot process argument transformation on
parameter 'test'. Cannot convert value "System.String" to type "System.Manageme
nt.Automation.SwitchParameter", parameters of this type only accept booleans or
numbers, use $true, $false, 1 or 0 instead.
At line:0 char:1
+ <<<<
+ CategoryInfo : InvalidData: (:) [test.ps1], ParentContainsError
RecordException
+ FullyQualifiedErrorId : ParameterArgumentTransformationError,test.ps1
그러나 한 때 나타나는 '및' 테스트 1 진정한 테스트 반군지역 '결과'. 왜 doesn& # 39, t 이 작동합니까? # 39, t, s 형 변환 shouldn& Powershell& # 39 를 자동으로 인식 시스템 또는 스위치, 이러한 문장열 部门是这样的 부울 전환사채 (cb) 로 변환하십시오?
즉 powershell) 으로부터 스크립트를 높여줍니까 호출할 때 다른 시스템 (시스템을 구축하는 등) 의 흐름 제어 구조가 복잡한 it& # 39 chunghwa 필요한 스위치, 또는 생략하십시오 명령 문자열의 포함 여부를 결정할 수 있어? 이 날 it& # 39 의 오류 발생 가능성이 높은 것으로 비효율적임 및 주도하고 있는 믿을 수 없는 경우.
List. 이스프레센트 재산에 스위치였습니다. 예:
function test-switch{
param([switch]$test)
function inner{
param([switch]$inner_test)
write-host $inner_test
}
inner -inner_test:$test.IsPresent
}
test-switch -test:$true
test-switch -test
test-switch -test:$false
True
True
False
브트와, 내가 아닌 기능을 사용할 수 있도록 스크립트입니다 약간만이라도 테스트하려면.