Hi all,
Hopefully another simple and quick one:
$legclusters = Import-Csv C:\output\legclusters.csv
get-cluster -name $legclusters.clusname | Get-DrsRule
This lists all the rules I want, but does not include the cluster name, so it becomes one big jumble. How do I include the $legcluster.name in the output?
The object returned by Get-DrsRule does contain the cluster object, including the ClusterName.
It might not show on your console, but it is there.
For example
Get-Cluster -Name $legcluster.clusname | Get-DrsRule |
Select Name,Enabled,Type,
@{N='VM';E={(Get-View -Id $_.VMIDs).Name -join '|'}},
@{N='Cluster';E={$_.Cluster.Name}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
The object returned by Get-DrsRule does contain the cluster object, including the ClusterName.
It might not show on your console, but it is there.
For example
Get-Cluster -Name $legcluster.clusname | Get-DrsRule |
Select Name,Enabled,Type,
@{N='VM';E={(Get-View -Id $_.VMIDs).Name -join '|'}},
@{N='Cluster';E={$_.Cluster.Name}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Rare I get to point out an error in your code but there is an extra 'r' in get-drsRrule , but otherwise correct as always.
Just so I don't keep coming back asking similar questions, I'm trying to understand this piece:
@{N='Cluster';E={$_.Cluster.Name}}
Is there an get-help I can reference or could you explain what's going on here? Specifically @{N=
I see it in select statements all the time, but I'm not exactly sure what's going on in in the code.
Well spotted, typo (and corrected).
There are 2 things you should know/learn:
- PS has the concept of a 'calculated property' that you can use on the Select-Object Property parameter.
This allows you to select properties that are normally not visible on screen (due to screen width or due to the XML definition that defines what is shown)
- To find out what is in an object returned by a PowerCLI cmdlet, you can use the PowerCLI Reference.
In this case the Get-DrsRule cmdlet.
On that page, most of the time, you will find under Output what object is returned.
When you clock on that link, VMware.VimAutomation.ViCore.Types.V1.Cluster.DrsRule in this case, you will see all the properties in that object.
Also, note that objects can be nested.
So is under the CLuster property a complete Cluster object, which includes the name of the cluster.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference