我编写了一个 Powershell 脚本,应该将服务设置为 StatusType = 'Automatic'。但是当我运行脚本时,它实际上设置了 StatusType = 'Automatic (Delayed Start)'。以下是我的脚本:-
Set-Service -name 'XXXXX Data Import Service' -startupType automatic
任何人都可以帮助我将 statusType 设置为 'Automatic' 吗?
我编写了一个 Powershell 脚本,应该将服务设置为 StatusType = 'Automatic'。但是当我运行脚本时,它实际上设置了 StatusType = 'Automatic (Delayed Start)'。以下是我的脚本:-
Set-Service -name 'XXXXX Data Import Service' -startupType automatic
任何人都可以帮助我将 statusType 设置为 'Automatic' 吗?
您可以这样做:请参阅我在脚本中提到的评论。相应地使用它。
#$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 之间的空格很重要。
我怀疑赢10。你不能用 set-service 做到这一点。需要使用 sc.exe 获得显式服务启动状态。
sc config "XXXXX Data Import Service" start= auto
使用 Window Server 2016 对我有什么帮助:
sc.exe config <service> start=auto
例如,sc.exe config aspnet_state start=auto
请注意,等号后不需要空格。