我面臨的問題是添加一個變量的循環計數,並將其傳遞給函數和打印細節。請提出你的明智建議。參數傳遞在PowerShell功能
我的代碼如下所示:
function CheckErrorMessage {
[CmdletBinding()]
Param (
[Parameter(Mandatory = $true, Position = 0)]
[ValidateNotNullOrEmpty()]
$Plugin
, [Parameter(Mandatory = $true, Position = 1)]
[ValidateNotNullOrEmpty()]
$Report_Decission
)
switch ($Plugin){
'plugin-1' {
$Report_Decission
}
'plugin-2' {
$Report_Decission
}
Default {
}
}
}#functions ends here
$test_1 = "no report"
$test_2 = "with report"
for($i=1; $i -ne 3; $i++){
CheckErrorMessage 'plugin-1' "$test_$i" # i want to sent $test_1 or $test_2 from here
CheckErrorMessage 'plugin-2' "$test_$i"
}
當我運行它,它打印
1
1
2
2
但我要像輸出:提前
no report
no report
with report
with report
感謝。
我可能會去'ExpandString()',而不是:''$ ExecutionContext.InvokeCommand.ExpandString( 「'$ TEST_ $ I」)''如果說 –
會高興IEX我的意思是一些細節它是如何工作的 –
@EricIpsum更新了鏈接 – 4c74356b41