PowerCLI

 View Only
  • 1.  Script Shutdown vCenter

    Posted Mar 04, 2021 09:28 AM

    Hi guys,

    I made a script by copying a little bit of here is a little bit of there to turn off all my vMware infrastructure.
    The script works fine, I only have some problems and we who would like to understand with you and maybe find a solution, I go in order:

    1) when it sends the command "Get-VM -Name" SRV01 "| shutdown-vmguest -Confirm: $ false" it takes more seconds than usual to shut down because it has more substantial services (database). So I would like to understand how to give it a maximum time, like if it takes more than 10 seconds run STOP-VM.

    2) I would like to have a log to see what happens and what went wrong. I am using Start-Transcript, but I don't find it efficient

    3) In case of errors I would like the script to stop and not continue to send further commands.


    I hope I was as clear as possible
    Thank you

    Moderator note by wila: Moved thread to VMware PowerCLI discussions



  • 2.  RE: Script Shutdown vCenter

    Posted Mar 04, 2021 09:49 AM

    Ciao 

    For the check if the VM is Power Off  I use this :

    $vmservers | Shutdown-VMGuest -Confirm:$false
    while((Get-VM -Server $vmservers | where{$_.PowerState -ne 'PoweredOff'}).Count -ne 0){
    sleep 5
    }

    You can insert after the command "sleep 10"  the STOP-VM 

    For the logs you can use Write-host to display info or save info to log file with  |  Out-File -FilePath c:\log.txt

    To stop the script at the error you can try to use -Erroraction Stop at the end of the single commands 

    Bye 

    Fabio 

     

     

     



  • 3.  RE: Script Shutdown vCenter

    Posted Mar 04, 2021 09:58 AM

    Thank you for the reply!!

    in my case the VMs are in the specific pool



  • 4.  RE: Script Shutdown vCenter

    Posted Mar 04, 2021 10:04 AM

    So you want to extract the list of vms of a pool and then turn them off?

    To view the vms of a pool you can try Get-ResourcePool -Name <Pool name> | Get-VM

     

    Bye Fabio



  • 5.  RE: Script Shutdown vCenter

    Posted Mar 04, 2021 10:12 AM

    no actually i turn off all the vm present in the pool, but if one of those takes 20 minutes i cannot wait.
    are you Italian??



  • 6.  RE: Script Shutdown vCenter

    Posted Mar 04, 2021 10:28 AM

    Yes 



  • 7.  RE: Script Shutdown vCenter

    Posted Mar 04, 2021 10:38 AM

    allora parliamo in italiano 



  • 8.  RE: Script Shutdown vCenter

    Posted Mar 05, 2021 10:29 AM

      do you have resolved? (hai poi risolto?)