【发布时间】:2014-07-22 18:02:43
【问题描述】:
到目前为止,我有我的 .ps1 文件
Param([Parameter(Mandatory=$true,ValueFromPipelin=$true)][string[]] $appPoolArray)
$zero = 0
if ($appPoolArray.length -eq $zero){
Write-Output "no app pools where selected"
exit
}
else {
foreach ($elem in $appPoolArray)
$appPool = Get-WmiObject -namespace "root\MicrosoftIISv2" -class "IIsApplicationPool" | Where-Object {$_.Name -eq "W3SVC/APPPOOLS/$elem"}
$appPool.Recycle()
Write-Output "Recycled."
Start-Sleep -Second 60
}
Write-Output "Done."
}
我想这样做,如果 cmd 行中没有参数,那么它会立即退出,相反,如果我在命令中没有包含参数,它只会要求我继续将元素添加到数组中(命令 I我在 cmd 行中运行的是 powershell -noexit path\script.ps1) 我对 Powershell 或一般脚本不是很好,但我知道错误与 if 语句有关。帮助将不胜感激
编辑:我尝试取出 Write-Mandatory=$True 但现在当我没有通过任何争论时它会给我一个错误
【问题讨论】:
标签: arrays powershell if-statement cmd powershell-2.0