Automation

 View Only
  • 1.  VM shutdown maintenance script

    Posted Sep 08, 2010 10:24 PM

    I'm trying to combine a few one liners into a single powercli script using PowerCLI 4.0 U1

    I am getting a list of all powered on VMs in a cluster (particular cluster I'm working on has all of its VMs on this single array) using this command:

    get-vm -Location DS | where {$_.powerstate -match "on"}

    I am getting a list of all datastores on this array based on our datastore naming convention. I'm sure there is a better way to do this but for now it works using this command:

    get-datastore | where {$_.name -like "dsname*"}

    I am also shutting down a list of VMs using this command:

    get-content c:\vm_list.csv | % { Get-VM $_ | Shutdown-VMGuest -confirm:$false }

    What I'd like to do is put these together into one script. I'm sure it's something simple but I'm not sure how to do it.

    So to summarize my goal is to have a script that will shutdown all VMs that are currently powered on on a particular array and then power these VMs back on.

    Thanks



  • 2.  RE: VM shutdown maintenance script
    Best Answer

    Posted Sep 08, 2010 11:09 PM

    Provided I got the question right, you can do something like this

    Get-Datastore -Name "dsname*" | Get-VM | where {$_.powerstate -match "on"} | Shutdown-VMGuest -confirm:$false
    

    It first gets all the datastores that match the naming, then it gets all the guest located on those datastores and for those guests that powered on it iniates a shutdown.

    ____________

    Blog: LucD notes

    Twitter: lucd22



  • 3.  RE: VM shutdown maintenance script

    Posted Sep 09, 2010 06:01 AM

    Great thanks. This is perfect.