I’ve written a Powershell script that shutdowns a remote
computer. This Powershell script use WMI to shutdown the remote system.
1. Open notepad
2. Copy and paste below text to notepad
3. Save the file with .ps1 extension.
# ---------- SCRIPT STARTS HERE--------------
#remote shutdown script
#usage remoteshutdown.ps1 computername
#usage remoteshutdown.ps1 computername
$objsystem = get-wmiobject -computername $args[0] -query
"select * from win32_operatingsystem"
$result = $objsystem.shutdown()
if ($result.returnvalue -match "0") {
write-host "$args[0] - shutdown command completed" -foregroundcolor green
}
else {
write-host "$args[0] - unable to send shutdown command" -foregroundcolor red
}
$result = $objsystem.shutdown()
if ($result.returnvalue -match "0") {
write-host "$args[0] - shutdown command completed" -foregroundcolor green
}
else {
write-host "$args[0] - unable to send shutdown command" -foregroundcolor red
}
# ---------- SCRIPT ENDSS HERE--------------
0 comments :
Post a Comment