PowerShell 脚本不会以本地用户或管理员身份运行

问题描述 投票:0回答:1

我有一个非常小的脚本来重新启动服务,不幸的是,我不确定为什么它不能正常工作。它是可执行的,但不会停止服务;因此不执行其他两行的函数。

# Stop the "serviceName" service
Stop-Service -Name "serviceName" -ErrorAction SilentlyContinue

# Wait for 10 seconds
Start-Sleep -Seconds 10

# Start the "serviceName" service
Start-Service -Name "serviceName"

我尝试使用以管理员身份运行的 PowerShell 从我的 .\Users\me\Desktop\ 执行脚本。

windows powershell scripting windows-server-2012
1个回答
0
投票

从第二行删除“-ErrorAction SilentlyContinue”有效。

© www.soinside.com 2019 - 2024. All rights reserved.