VMware Cloud Community
AutoEng
Contributor
Contributor

vSAN report on storage policy and DRS site affinity membership

Hi all,

I run a large vSAN stretched cluster. I constantly run into problems with admins creating VMs in a site, and then assigning the wrong storage policy, e.g. VM is in site B but has storage policy with local protection for site A.

Having a look through the PowerCLI cookbook for vSAN, I found a useful script for reporting on a VMs storage policy compliance:

PowerCLI-Cookbook-For-vSAN-v1.7

However, I need assistance to add the DRS site-affinity membership to the above script, so that I have a report showing a VMs storage policy, and its associated site affinity.

Thanks in advance for your assistance.

Reply
0 Kudos
8 Replies
LucD
Leadership
Leadership

Which script from that document are you referring to?

Can you provide some more information on the site affinity part?

What exactly do you mean by that?

Perhaps a Web CLient screenshot could help to explain?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
AutoEng
Contributor
Contributor

Hello,

It is the Per-VM Storage Policy Compliance script on page 104.

I am referring to the site affinity in a vSAN stretched cluster, the DRS rules, which consist of VM/Host groups and VM/Host rules as per the below:

https://storagehub.vmware.com/t/vmware-vsan/vsan-stretched-cluster-guide/configure-stretched-cluster...

So there would be the Preferred Site and the Secondary Site.

Someone creates a VM, say with local protection in the Secondary Site, and the VM is not stretched, but they locate the VM in the Preferred Site by making it a member of the VM/Host rules for the Preferred site.

It would be useful to have the above script, also show which DRS rules the VM is a part of, so we can check for mistakes that I have described above.

I can send you a screenshot directly if that will help, I cannot share them on a public forum.

Reply
0 Kudos
LucD
Leadership
Leadership

If I read that document correctly, the Site concept is a kind of convention.

Not sure if that can be automated without specifying extra information on the relations between VM, StoragePolicy, Sites and the DRS rules.

You can easily add the DRS rule for a VM.

That should, following that document, give you the name of the rule (ShouldRunSiteA).

$Cluster = Get-Cluster

$VMs = $Cluster | Get-VM | Sort-Object Name

$results = @()

Foreach ($VM in $VMs) {

    $VmCompliance = Get-SpbmEntityConfiguration -VM $VM

    $VmTmp = [PSCustomObject] @{

        VM          = $VmCompliance.Name + "-Namespace"

        DrsRule     =  (Get-DrsRule -Cluster $Cluster -Type VMHostAffinity -VM $VM).Name

        Policy      = $VmCompliance.StoragePolicy

        Status      = $VmCompliance.ComplianceStatus

        TimeofCheck = $VmCompliance.TimeOfCheck

    }

    $results += $VmTmp


    $HardDisks = Get-HardDisk -VM $VM

    Foreach ($HardDisk in $HardDisks) {

        $HdCompliance = Get-SpbmEntityConfiguration -HardDisk $HardDisk

        $HdTmp = [PSCustomObject] @{

            VM          = $VmCompliance.Name + "-" + $HdCompliance.Name

            DrsRule     =  (Get-DrsRule -Cluster $Cluster -Type VMHostAffinity -VM $VM).Name

            Policy      = $HdCompliance.StoragePolicy

            Status      = $HdCompliance.ComplianceStatus

            TimeofCheck = $HdCompliance.TimeOfCheck

        }

        $results += $HdTmp

    }

}

$results | Format-Table


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
AutoEng
Contributor
Contributor

Thanks I will have a look at that over the weekend and let you know.

Reply
0 Kudos
AutoEng
Contributor
Contributor

Hello,

It works well, thanks for your assistance. I'm trying to export the output to csv with " | export-csv" however the output is not legible. Do you know what I need to do to get the csv export working?

Reply
0 Kudos
LucD
Leadership
Leadership

Not too sure what you mean by "... not legible", but did you do the export like this?

$results | Export-Csv -Path .\report.csv -NoTypeInformation -UseCulture


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
AutoEng
Contributor
Contributor

Just a long string of numbers on each line.

I was missing the "$results" ... I'll try again with that.

Reply
0 Kudos
LucD
Leadership
Leadership

If it doesn't work, show me an anonymised example of what you are seeing.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos