Quantcast
Channel: VMware Communities: Message List
Viewing all articles
Browse latest Browse all 252940

Re: VC's inventory using powercli

$
0
0

I did some rewriting to improve the speed of the script. The problem was that for every virtual machine the Get-View cmdlet was called to retrieve the host and all the datastores. This takes a lot of time if you do it 8000 times. So I moved these Get-Views calls outside of the loop. Now the Get-View cmdlet has only to be called three times for each vCenter server.The first time to create a hashtable with the hostnames. The second time to create a hashtable with the datastore names. And the third time to get the virtual machines. In my environment with 3 vCenter servers, 41 hosts and 567 virtual machines the time to run the script went down from 9 minutes 15 seconds to only 5 seconds.This is 111 times faster. This means that the new script will probably run in about 32 minutes or less in your environment.

 

To run the script as a scheduled task take a look at: Running a PowerCLI Scheduled task.

 

& { foreach ($vCenterServerin$DefaultVIServers)    {      $VMHostTable= @{}      foreach ($VMHostViewin (Get-View-Server$vCenterServer-ViewTypeHostSystem-PropertyName))      {        $VMHostTable["$($VMHostView.MoRef.Value)"] =$VMHostView.Name      }      $DatastoreTable= @{}      foreach ($DatastoreViewin (Get-View-Server$vCenterServer-ViewTypeDatastore-PropertyName))      {        $DatastoreTable["$($DatastoreView.MoRef.Value)"] =$DatastoreView.Name      }      Get-View-Server$vCenterServer-ViewTypeVirtualMachine-Filter @{"Config.Template"="False"} -Property Name,        Runtime.Host,        Guest.GuestFullName,        Config.Annotation,        Datastore,        Config.Tools.ToolsVersion |      Select-Object-Property @{N="vCenter";E={$vCenterServer.Name}},        @{N="VMHost";E={$VMHostTable["$($_.Runtime.Host.Value)"]}},        @{N="VM";E={$_.Name}},        @{N="Guest OS";E={$_.Guest.GuestFullName}},        @{N="Notes";E={$_.Config.Annotation}},        @{N="Datastores";E={             $DatastoreNames=foreach ($Datastorein ($_.Datastore))              {$DatastoreTable["$($Datastore.Value)"]}                       [string]::Join(',',($DatastoreNames))           }         },        @{N="VMware Tools version";E={$_.Config.Tools.ToolsVersion}}    }  } |Export-Csv-Path"VMsInfo-$(Get-Date -UFormat '%Y%m%d-%H.%M.%S').csv"-NoTypeInformation-UseCulture

Viewing all articles
Browse latest Browse all 252940

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>