Thursday, 2 June 2016

How to reboot multiple Virtual Machines on an ESXi host

Recently I got a request to schedule the reboot of multiple VMs on an ESXi host on every weekend.

Let me explain the scenario first. 

1. We need to schedule the reboot of all 50 VMs on every Saturday at 10.00PM (all those machines are Windows servers)

2. Both ESXi and vCenter are version 5.5

3. PowerCLI is installed on vCenter server.



Step-by-step Instructions


1. RDP to your vCenter server (if you are using vCenter server appliance you need to make changes on the below steps accordingly)

2. Make sure that you have enabled access for your domain user (domain administrator)\local server administrator so that they can access vCenter. If you haven't done this please follow https://virtuallylg.wordpress.com/2013/09/29/vsphere-5-5-how-to-add-domain-users-to-sso/

3. Open a notepad and copy paste the below script, save the file as 'VMReboot.ps1'

param(
    [parameter(Mandatory = $true)]
    [string[]]$vCenter,
    [parameter(Mandatory = $true)]
    [string[]]$vmName
)

$VIServer = Connect-VIServer $vCenter
If ($VIServer.IsConnected -ne $true){
    Write-Host "error connecting to $vCenter" -ForegroundColor Red
    exit
}

foreach($vm in $vmName){
        Write-Host "Going to restart $vm"
        Restart-VMGuest -VM (Get-VM $vm) -Confirm:$false
}

Disconnect-VIServer -Confirm:$false


4. Open PowerShell and test the script first (see below screenshot).


You need to mention your vCenter server and name of VMs you need to reboot. If you have multiple VMs separate the names with comma or if all VMs start with a common prefix use wild card (eg. "TestVM*")

See the VMs you have mentioned are getting rebooted. If the script works then schedule this job using Windows Task Scheduler

5. Open Task Scheduler and Create a basic task 

6. Mention your schedule and on Actions > Start a Program

Program/script : C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe

Add arguments-PSConsoleFile "C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\vim.psc1" " &  "C:\VMReboot.ps1" -vCenter VCENTER-SRV -vmName "TestVM*"


Verify if the scheduled task is working by running it.

Enable Task History to make sure that the scheduled task is working properly



All the best!

31 comments:

  1. Thanks for the informative article. This is one of the best resources I have found in quite some time. Nicely written and great info. I really cannot thank you enough for sharing.

    Herbalife in Chennai
    Wellnesscentres in Chennai
    Weight loss in Chennai
    Weight gain in Chennai

    ReplyDelete
  2. Your site is amazing and your blogs are informative and knowledgeable to my websites.This is one of the best tips in my life.I have in quite some time.Nicely written and great info.Thanks to share the more information's.

    Seo Experts
    Seo Company
    Web Designing Company
    Digital Marketing
    Web Development Company
    App Development

    ReplyDelete
  3. Testers can build, enhance, and maintain scripts to regression test their mobile applications. Hands-on instruction is provided for those who want to explore the power of using Appium. The course covers content from installation to execution and reporting . The focus is on the practical application of Appium to resolve common mobile automated testing challenges. This course focuses on getting started with Appium.
    course/appiumtraininginsholinganallur/

    ReplyDelete
  4. As you have now understood the usage of ‘Record and Playback’ tool, the following are the different posts using which you can explore the functioning of ‘Selenium IDE’
    selenium Training in chennai

    ReplyDelete
  5. All the latest updates from the Python Automationminds team. Python Automationminds lets you program in Python, in your browser. No need to install any software, just start coding straight away. There's a fully-functional web-based console and a programmer's text-editor
    Phyton training in Chennai

    ReplyDelete
  6. Its very impressive post please continue posting like this and if you are interested please find or refer the links to get updates relevant to interior designs and approaches from:
    Leading Architects in India
    Turnkey Interior Contractors in Chennai
    Architecture Firms in Chennai
    Warehouse Architect
    Factory Architect Chennai
    Office Interiors in Chennai
    Rainwater Harvesting chennai
    Turnkey Interior Contractors in Chennai

    ReplyDelete
  7. Now it is known to me that articles is nothing but inspiring is everything to do something great. This is a great article for the people who want to come in freelancing.
    Asset Management Software
    Asset Tracking Software
    Asset Management Software India
    Asset Management Software Chennai

    ReplyDelete
  8. This blog is the general information for the feature. You got a good work for these blog.We have a developing our creative content of this mind.Thank you for this blog. This for very interesting and useful.
    python course institute in bangalore
    python Course in bangalore
    python training institute in bangalore

    ReplyDelete
  9. Thanks for the good words! Really appreciated. Great post. I’ve been commenting a lot on a few blogs recently, but I hadn’t thought about my approach until you brought it up. 
    Best Devops training in sholinganallur
    Devops training in velachery
    Devops training in annanagar
    Devops training in tambaram

    ReplyDelete

  10. Learn about other Apache projects that are part of the Hadoop ecosystem, including Pig, Hive, HBase, ZooKeeper, Oozie, Sqoop, Flume, among others. Big Data University provides separate courses on these other projects, but we recommend you start here.

    Bigdata training in Chennai OMR

    ReplyDelete
  11. Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging.
    rpa training in Chennai | rpa training in bangalore | best rpa training in bangalore | rpa course in bangalore | rpa training institute in bangalore | rpa training in bangalore | rpa online training

    ReplyDelete
  12. Howdy, would you mind letting me know which web host you’re utilizing? I’ve loaded your blog in 3 completely different web browsers, and I must say this blog loads a lot quicker than most. Can you suggest a good internet hosting provider at a reasonable price?
    Best AWS Amazon Web Services Training in Chennai | Best AWS Training and Certification for Solution Architect in Chennai
    Amazon Web Services Training in Tambaram, Chennai|Best AWS Training in Tambaram, Chennai

    ReplyDelete
  13. nice work keep it up thanks for sharing the knowledge.Thanks for sharing this type of information, it is so useful.
    cement bonder manufacturer in delhi

    ReplyDelete
  14. Thanks for giving great kind of information. So useful and practical for me. Thanks for your excellent blog, nice work keep it up thanks for sharing the knowledge.
    Best Interior Designer in Noida

    ReplyDelete
  15. Indoor LED Wall Lights in delhi
    Thanks for giving great kind of information. So useful and practical for me. Thanks for your excellent blog, nice work keep it up thanks for sharing the knowledge.

    ReplyDelete
  16. Thanks for sharing such an amazing blog. It is really helpful for me and I get my lots of solution with this blog. Thank you for sharing valuable information. Nice post. I enjoyed reading this post…
    Painting Services in Delhi

    ReplyDelete
  17. After reading this web site I am very satisfied simply because this site is providing comprehensive knowledge for you to audience.
    Thank you to the perform as well as discuss anything incredibly important in my opinion. We loose time waiting for your next article writing in addition to I beg one to get back to pay a visit to our website in



    selenium training in Bangalore
    selenium training in Marathahalli
    selenium training in Btm layout
    selenium training in Jaya nagar
    selenium training in Electronic city
    selenium training in Kalyan nagar



    ReplyDelete
  18. Your good knowledge and kindness in playing with all the pieces were very useful. I don’t know what I would have done if I had not encountered such a step like this.
    microsoft azure training in bangalore
    rpa training in bangalore
    best rpa training in bangalore
    rpa online training

    ReplyDelete
  19. I get my lots of solution with this blog. Thank you for sharing valuable information. Nice post. I enjoyed reading this post…
    Love Problem Solution in Delhi

    ReplyDelete
  20. we have provide the best fridge repair service.
    fridge repair in faridabad
    Bosch Fridge Repair in Faridabad
    Godrej Fridge Repair in Faridabad
    Haier Fridge Repair in Faridabad
    Videocon Fridge Repair in Faridabad
    ---------------------===============================================================================================

    ReplyDelete
  21. I feel happy about and learning more about this topic. keep sharing your information regularly for my future reference. This content creates new hope and inspiration within me. Thanks for sharing an article like this. the information which you have provided is better than another blog.
    Best IELTS Coaching in Dwarka sector 7

    ReplyDelete