Powershell 停止服务赢得';停不下来
我正在制作菜单,其中一个选项是根据服务的显示名称停止或启动服务。Powershell 停止服务赢得';停不下来,powershell,Powershell,我正在制作菜单,其中一个选项是根据服务的显示名称停止或启动服务。 当我想停止它时,它只是再次启动服务 $Display = Read-Host -Prompt 'Please enter displayname: ' $Choice = Read-Host -Prompt 'Would you like to start or stop the service' If (($Choice = 'start')) { Start-Service -displayname $Display
当我想停止它时,它只是再次启动服务
$Display = Read-Host -Prompt 'Please enter displayname: '
$Choice = Read-Host -Prompt 'Would you like to start or stop the service'
If (($Choice = 'start')) {
Start-Service -displayname $Display
Write-Host $Display "Starting..." -ForegroundColor Green
}
ElseIf (($Choice = 'stop')) {
Stop-Service -displayname $Display
Write-Host $Display "Stopping..." -ForegroundColor Green
}
问题在于当您应该使用
-eq
测试等式时,您正在使用=
的if
语句
您的代码正在设置变量,因此这两条语句始终为true。例如,你应该改为:
If ($Choice -eq 'stop') {