VMware Cloud Community
JDMils_Interact
Enthusiast
Enthusiast

Need help getting the output of this script to correctly display

I want to record the Automation Level of each cluster in the current vCenter and am using the script below:

	$Clusters= get-cluster
	$x = foreach($Cluster in $Clusters)
		{
		$ClusterDRS = $Cluster.DrsAutomationLevel
		Select $Cluster, $ClusterDRS
		}
	$x

I keep getting this error:

Select : Cannot convert VMware.VimAutomation.ViCore.Impl.V1.Inventory.ClusterImpl to one of the following types {System.String, System.Management.Automation.ScriptBlock}.
At line:4 char:1
+ Select $Cluster, $ClusterDRS
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Select-Object], NotSupportedException
+ FullyQualifiedErrorId : DictionaryKeyUnknownType,Microsoft.PowerShell.Commands.SelectObjectCommand

I want the output to be 2 columns consisting of Cluster Name and the Automation Level. Can you help me get this right?

Reply
0 Kudos
4 Replies
LucD
Leadership
Leadership

Try with

Get-Cluster | Select Name,DrsAutomationLevel


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

Reply
0 Kudos
JDMils_Interact
Enthusiast
Enthusiast

Thank you so much, that's a great help.

Now considering that the block of code I posted is very large and has many other statements (irrelevant to this question), how do I write that info to the screen based on the code I posted?

Sorry, I'm a real noob with PowerCli.

Reply
0 Kudos
LucD
Leadership
Leadership

You mean something like this?

$Clusters = Get-Cluster
foreach ($Cluster in $Clusters) {
    $cluster | select Name,DrsAutomationLevel
}


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

Reply
0 Kudos
JDMils_Interact
Enthusiast
Enthusiast

Yeah, that's awesome! Thanks.

Reply
0 Kudos