2 Replies Latest reply on Jan 23, 2019 7:32 AM by vijayku

    Any idea how to optimize this script/function please ?

    Soji42 Lurker


      I wrote this function to get the inventory below on all VMs from VSAN.


      The thing is ... it takes like 3 or 4 hours to complete a list of 1000 VM.


      Do you know how I can optimize my script so it will proceed faster ?

      cmdlet Get-VsanObject is only available in PowerCLI 11.


      Function        vmStoragePolicy {


              $list = foreach ($vm in $vmlist){

                      $vsan = Get-VsanObject -VM $vm | Select VM, Cluster, StoragePolicy, ComplianceStatus

                      $da = Get-VM $vm | Get-Datastore


                              "VM" = $vm

                              "Datastore" = $da.Name

                              "Cluster" = ($vsan.Cluster.Name | Out-String).Trim()

                              "Storage Policy" = ($vsan.StoragePolicy.Name | Out-String).Trim()



              return $list



      $vmlist = Get-Content "/root/vmvsan.txt"

      vmStoragePolicy -vm $vmlist | Export-CSV -Delimiter ";" -Path $file

      Thanks for your help guys.