How to Shutdown a remote computer using Powershell Script

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

$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
}

# ---------- SCRIPT ENDSS HERE--------------