Showing posts with label Powershell Script to Start all Stopped Services. Show all posts
Showing posts with label Powershell Script to Start all Stopped Services. Show all posts

Powershell Script to Start all Stopped Services

By // No comments :


I’ve written a Powershell script that starts all stopped services from list of remote computers. This script can be very helpful after power outages.
1. Open notepad
2. Copy and paste below text to notepad
3. Save the file with .ps1 extension.
USAGE: c:\startallservices.ps1 c:\computerlist.txt
# ---------- SCRIPT STARTS HERE--------------
$inputfile = Dir $args[0]
$readinputfile = get-content $inputfile
$readinputfile | ForEach-Object {
$objstoppedservices = get-wmiobject -computername $_ -query "select * from win32_service where state='stopped' and startmode='auto'"
foreach ($service in $objstoppedservices) {
$result = $service.startservice()
if ($result.returnvalue -match "0") {
write-host "$service on $_ is started" -foregroundcolor green
}
else {
write-host "$service on $_ cannot start" -foregroundcolor red
}
}
}
# ---------- SCRIPT ENDSS HERE--------------


Ads by Google

Copyright by SudoLumo Inc. Powered by Blogger.

TopMenu

Sponsors