PowerCLI

  • 1.  What is the fastest way to get a VMs and the SPBM policy?

    Posted 3 days ago
    Edited by MattGGS 3 days ago

    Trying to create a daily report of VMs and what SPBM they belong to.   I have tried looping through all VMS:

    $vm|Get-SpbmEntityConfiguration 

    As well a collecting all policies with associated VMs:

    Get-SpbmStoragePolicy |Get-SpbmEntityConfiguration -VMsOnly

    Either way it is very slow.   Wondering if I am missiing something or if I should expect that getting the SPBM policy for 8000 VMs should take over an hour?

    Thanks,



  • 2.  RE: What is the fastest way to get a VMs and the SPBM policy?

    Posted 2 days ago
    Edited by ITSavant 2 days ago

    I have about 150K VMs, so I understand your pain, I ran this against one VC with about 7800 VMs and it returned in about 13 seconds.


    I cheated on the output objects a bit, but this might get you the data you are looking for:


    $vSanDataStoreViews = Get-View -ViewType Datastore -Server $vCenter -Property Name, 'Summary.Type' | ?{$_.Summary.Type -eq "vsan"}
    $DataStoreSpbmEntityConfigurations = $vSanDataStoreViews | %{Get-SpbmEntityConfiguration -Datastore (Get-DataStore -ID $_.MoRef -Server $_.Client.ServiceUrl.Split('/')[2]) -Server $_.Client.ServiceUrl.Split('/')[2]}
    $VMViews = Get-View -ViewType VirtualMachine -Server $vCenter -Property Name, Datastore
    $OutPutItems = [System.Collections.Generic.List[PSobject]]@()
    ForEach($VMView in $VMViews){
        ForEach($VMViewDatastore in $VMView.Datastore){
            $DataStoreSpbmEntityConfiguration = $Null
            IF($DataStoreSpbmEntityConfigurations.Id -Contains $VMViewDatastore){
                $DataStoreSpbmEntityConfiguration = $DataStoreSpbmEntityConfigurations | ?{$_.ID -eq $VMViewDatastore} | ?{$_.Uid.Split('@')[1].Split(':')[0] -eq $VMView.Client.ServiceUrl.Split('/')[2]}
                IF($DataStoreSpbmEntityConfiguration){
                    $OutPutItems += [PSCustomObject]@{
                        TimeOfCheck = Get-Date
                        ComplianceStatus = "unknown"
                        Entity = $VMView.Name
                        StoragePolicy = $DataStoreSpbmEntityConfiguration.StoragePolicy
                        ReplicationGroup = $Null
                        Name = $VMView.Name
                        Id = $VMView.MoRef
                        Uid = "$($DataStoreSpbmEntityConfigurations[0].Uid.Split('=')[0..1] -join '=')=$(($VMView.MoRef).ToString())/"
                    }
                }
            }
        }
    }

    $OutPutItems