Sureshadmin
Contributor
Contributor

Need vCenter management scripts

Jump to solution

Hi,

I need powershell scripts to perform below given tasks,

1. Script to power on all the powered off vm's in a cluster with a criteria of 2 vm's power on at any given point of time and the remaining vm's follow as the running power on tasks complete.

2. Script to get the count of virtual machines in vcenter classified by guest OS. Please note vmware tools are installed in all the machines.

Example:

Guest OS VM count

Windows XP Professional 50

Windows 2003 server 40

3. Script to give a count of esx servers in a vcenter classified by their version and build number.

Example:

Version(build) Count

3.5.0(176894) 12

3.5.0(199239) 10

4. Script to get count of virtual machine in each folder with datacenter name.

Datacenter_name | Foldername | vmcount

5. Script to get Overall Count Statistics from vcenter

Total Datacenters:

Total Clusters:

Total ESX Hosts:

Total VM's:

Total Templates:

Total LUN Datastores:

Total Size of LUN Datastores in GB:

Thanks in advance!

0 Kudos
23 Replies
RvdNieuwendijk
Leadership
Leadership

I have checked and changed the script. I even managed to test it. It now starts the powered off VM's with a maximum of two at the same time:

Get-Cluster <MyCluster> | `
  Get-VM | `
  Where-Object {$_.PowerState -eq "PoweredOff"} | `
  ForEach-Object {
    while ((Get-Task | Where-Object {($_.Name -eq "PowerOnVM_Task" -or $_.Name -eq "PowerOnMultiVM_Task") -and $_.PercentComplete -ne 100}).Count -ge 2) {
      Start-Sleep -Seconds 5
    }
    Start-VM -VM $_ -RunAsync
}

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition

View solution in original post

0 Kudos
Sureshadmin
Contributor
Contributor

Robert,

Yes, this script is working fine and also its very useful for me. Thanks a lot.

0 Kudos
sbrad001
Contributor
Contributor

Great script!  Is it possible to modify this a bit to only report back on folder with more than say 10 VMs?  I am looking for a way to keep an eye on those folders that have a large number of VMs.

Thanks!

0 Kudos
justinsmith
Enthusiast
Enthusiast

This is a great quick script... is there a way to get ONLY NFS storage or SAN attached storage? 

0 Kudos