Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell 停止服务赢得';停不下来_Powershell - Fatal编程技术网

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') {