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

AWS Certification Q&A

The AWS Certified Solutions Architect – Associate Level exam is intended for individuals with experience designing distributed applications and systems on the AWS platform. I am listing many sample certification questions and answers while will help to face the certification successfully Keep in mind that the answers for each question might change due to the advancement of AWS and please try to find the answer in more logical manner Answers are below of the page Sample Questions for Amazon Web Services Associate Solutions Architect Certification What does Amazon S3 stand for? A Simple Storage Solution. B Storage Storage Storage (triple redundancy Storage). C Storage Server Solution. D Simple Storage Service. You must assign each server to at least _____ security group A 3 B 2 C 4 D 1 - Before I delete an EBS volume, what can I do if I want to recreate the volume later? A Create a copy of the EBS volume (not a snapshot) B Store a snapshot of the volume C Downlo...