Skip to main content

Powershell script to remote reboot servers

$RebootList = Get-Content RebootServers.txt
foreach( $Rsrv in $RebootList )
{
Write-host “Issuing remote reboot command to $Rsrv”
# Command to force reboot the remote server
(gwmi Win32_OperatingSystem -ComputerName $Rsrv).Win32Shutdown(6)
}
That’s all. You can replace the (6) with any of the following:
0 = Log off
1 = Shutdown
2 = Reboot
8 = Power off
4 = Forced log off
5 = Forced shutdown
6 = Forced reboot
12 = Forced power off

*******************************************  
Note:

1. Create a text file – in this case RebootServers.txt
2. Populate RebootServers.txt with the names of the servers you want to reboot. One server name per line. Make sure there are no blank lines after the last server name.
3. Save the RebootServers.txt file in the same directory as the PS1 script (like the one you created – RemoteShutDown.ps1)
4. Run the script to reboot servers.

Comments

Popular posts from this blog

Installing Nagios 4 on Ubuntu 14 04 LTS

Embedding IAM roles in EC2 instances

http://searchaws.techtarget.com/tip/Embedding-IAM-roles-in-EC2-instances Many enterprises know that turning off unused AWS instances can save money. But not all IT pros know which method is best and how to set it up. There are a few ways to turn off unused Amazon Web Services (AWS) Elastic Compute Cloud (EC2) instances. If you don't use Auto Scaling, you will need to configure this process manually. One method is to use command-line interface (CLI) tools ec2-start-instances and ec2-stop-instances on Linux, using either a role-based method or an identity access management user-credential method. Setting up role-based security enables you to associate AWS identity and access management (IAM) roles with the instance, without having to manually add plain-text security credentials. This not only improves security, but is easier to manage. Identify an instance that will perform CLI start and stop scripts, or create a dedicated micro-instance to perform these maintenance tasks. IA...