2

我编写了一个 Powershell 脚本,应该将服务设置为 StatusType = 'Automatic'。但是当我运行脚本时,它实际上设置了 StatusType = 'Automatic (Delayed Start)'。以下是我的脚本:-

Set-Service -name 'XXXXX Data Import Service' -startupType automatic

任何人都可以帮助我将 statusType 设置为 'Automatic' 吗?

4

3 回答 3

1

您可以这样做:请参阅我在脚本中提到的评论。相应地使用它。

#$server is the server name you want to change
#$service is the service name
$command = "sc.exe \\$server config $service start= delayed-auto" ## For delayed Auto
$command = "sc.exe \\$server config $service start= auto"## For Automatic
$output = invoke-expression -command $command
write-host $server " " $output

注意: start=delayed-auto 之间的空格很重要。

于 2016-12-07T14:16:44.107 回答
1

我怀疑赢10。你不能用 set-service 做到这一点。需要使用 sc.exe 获得显式服务启动状态。

sc config "XXXXX Data Import Service" start= auto
于 2016-12-07T13:34:10.230 回答
0

使用 Window Server 2016 对我有什么帮助:

sc.exe config <service> start=auto

例如,sc.exe config aspnet_state start=auto

请注意,等号后不需要空格

于 2019-04-18T12:14:07.170 回答