VMware Cloud Community
Sureshadmin
Contributor
Contributor
Jump to solution

Need vCenter management scripts

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
Jump to solution

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
0 Kudos
Sureshadmin
Contributor
Contributor
Jump to solution

Robert,

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

0 Kudos
sbrad001
Contributor
Contributor
Jump to solution

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
Jump to solution

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

0 Kudos