2016-12-07 76 views
1

我寫了一個Powershell腳本,該腳本應該將服務設置爲StatusType ='Automatic'。但是當我運行這個腳本時,它實際上設置了StatusType ='Automatic(Delayed Start)'。以下是我的腳本: -Powershell - 將服務StatusType設置爲'自動'

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

任何人都可以幫助我設置statusType只是'自動'?

+1

除非服務很關鍵,並且在計算機啓動時需要運行**絕對**,所以使用延遲啓動更可取,因爲它有助於避免多個服務全部啓動時資源的爭奪。延遲啓動服務一次排隊並啓動一次,因此不會對資源產生這樣的影響。 –

回答

1

贏10我懷疑。你無法使用set-service。需要使用sc.exe來顯式啓動服務。

sc config "XXXXX Data Import Service" start= auto 
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 

注:空間是開始=延遲自動之間重要的。

+0

非常感謝您的幫助朋友:-)。我在你的幫助下工作。 – ED209

+1

@ ED209:請接受這種情況下的答案。 –