VMware Cloud Community
Mallik7
Enthusiast
Enthusiast

Need PowerCLI script to know if any Affinity rules applied on any Cluster or host

I'm in need of a PowerCLI script to get the detailed information about all the DRS rules which are applied / configured in my environment. There are about 10 vCenters in my Customer environment. Output to be saved in .csv format (date and time to be captured in the output file name along with vCenter name) and the each cluster wise or host wise information required. Can you help?

TIA

0 Kudos
7 Replies
LucD
Leadership
Leadership

Try something like this.
Do you need more info in the output?

$report = foreach($vc in $global:DefaultVIServers){

    foreach($cluster in Get-Cluster -Server $vc){

        Get-DrsRule -Cluster $cluster |

        Select @{N='vCenter';E={$vc.Name}},

            @{N='Cluster';E={$cluster.Name}},

            Name,Type,Enabled

    }

}

$report | Export-Csv -Path ".\DRSRule-Report-$(Get-Date -Format 'yyyyMMdd-HHmm').csv" -NoTypeInformation -UseCulture


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

0 Kudos
Mallik7
Enthusiast
Enthusiast

sorry to say, it is not working as expected. Some errors while running the script. Can you please correct them !!

throwing an error here

+ @{N='Cluster';E={$cluster.Name}},

+                                  ~

Missing expression after ','.

    + CategoryInfo          : ParserError: (:) [], ParseException

    + FullyQualifiedErrorId : MissingExpressionAfterToken

0 Kudos
LucD
Leadership
Leadership

Looks like you are missing some lines.

How are you running this, from a .ps1 file?

Did the copy/paste of the lines work correctly?

Perhaps attach your .ps1 file so I can have a look.


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

0 Kudos
Mallik7
Enthusiast
Enthusiast

please find attached

0 Kudos
LucD
Leadership
Leadership

Ok, you rearranged the properties on the Select cmdlet, but you didn't change the commas at the end of the lines.

Try attached


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

0 Kudos
Mallik7
Enthusiast
Enthusiast

thanks, it is working. How to add / connect all the vCenters at a time to the script instead using Connect-VIServer command ?

if can be added to the script it self, please advise..!

and will this script grabs information about the Virtual Machine options as well ? (Fully Automated or Manual) etc

0 Kudos
LucD
Leadership
Leadership

You can add a line at the beginning, connecting to all the vCenters.

Something like

Connect-CIServer -Server vc1,vc2,vc3

No, the script currently only reports on the rules (like I said earlier).
If you want other info the report, the script needs to be amended.

But reflect on how you want to display that info in the report.


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

0 Kudos