Get-drsrule enhancement


I was doing some drs rules today and noticed( after all those years 😉 ) that i get only id’s for vms in output. So i can not see directly which vms for example are set to be together etc…
In order to quickly have the output with the names instead of ids i wrote this tiny enhancement:

get-cluster XXX | Get-DrsRule | select Name, KeepTogether,Enabled, @{N="VMnames";E={ $_.Vmids|%{(get-view -id $_).name} } } 

*
I got a comment today under this post, so i thought i could just put the ‘normal/better’ version of this, since clearly this one does not make sort of logical sense, i mean of course it works, but it is really ugly because of the foreach of vmids , this is really ‘not the best idea’ to run get-view so many times if one can run it just once.

get-cluster |Get-DrsRule | select Name, KeepTogether,Enabled, @{N="VMnames";E={ (get-view -id $_.vmids).name } }

So this is more elegant plus it is actually way faster than the previous one.
They might look really similar to you, but in fact those are 2 different approaches.
The first one does a loop on an array of vmids and each iteration it asks get-view to fetch data.
The latter one is asking get-view just once, as we can pass to it ALL the vm ids. in the old day i would also do a param -property name for the get-view itself but these days (2020) the powercli is so much better optimized compared to 2012… then i dont see even a speed difference.
If the output is not optimized you can always use |ft -autosize at the end of the line.
For each of the virtual machine id i get the vm view and take its name.
You can do get-vm -id or get-view -id. If there is small amount of vms in your rules, that would not affect any performance of this command.
Tiny enhancement but saves some time on checking those ids manually.

3 thoughts on “Get-drsrule enhancement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s