2 Replies Latest reply on Aug 15, 2017 6:29 PM by nicholas1982

    Shutdown VM Resize and PowerOn from CSV

    nicholas1982 Hot Shot

      Hi All,

       

      I would like to shutdown VM's resize CPU and Memory and Poweron from a CSV list, I would like to be able to set a sleep time between each VM

       

      CSV would look like this:

       

      VMname,vCPU,vMemMB

      server1,2,4096

      server2,4,8192

      server2,8,16384

       

      Could someone kindly assist?

        • 1. Re: Shutdown VM Resize and PowerOn from CSV
          CRad14 Hot Shot

          I probably won't give you the whole thing, but I can provide some structure and the basics

           

           

           

          $csv= import-csv ./csvname.csv

           

          ForEach ($row in $csv)

               {

              $vm = get-vm $row.vmname

               $vm | Shutdown-VMguest

           

               do {

                #Wait 5 seconds

                Start-Sleep -s 5

                #Check the power status

                $MyVM = Get-VM $vm

                $status = $MyVM.PowerState

             }until($status -eq "PoweredOff")

              

               $vm | set-vm -memorymb $row.memmb -numcpu $row.vcpu

               start-sleep - 10

               $vm | Start-VM

               }

           

           

           

          That should be most of it....Definitely isn't built for speed, and I didn't check syntax really...but it should be mostly there...

          I pulled the do loop from https://isjw.uk/shutting-down-a-virtual-machine-using-powercli/  because I am lazy

           

          Hope that helps

          2 people found this helpful
          • 2. Re: Shutdown VM Resize and PowerOn from CSV
            nicholas1982 Hot Shot

            Thanks CRad14, I actually started writing something but just not confident on my scripting but this this makes sense. Cheers I really appreciate your response.