VMware Cloud Community
a2alpha
Expert
Expert
Jump to solution

cluster count not working in 3.5

Hi, I am running a script on a vSphere environment and when using the following line it works fine however when I run it on 3.5 it just leaves a blank. When running the line direct in the vi-toolkit it doesn't return anything suggesting that count is not an option.

$cluster = get-cluster

$cluster.count

Is there an alternative method of counting the number of clusters which would work for both vSphere and 3.5.

Thanks,

Dan

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

This should work on 3.5 and vSphere.

Could it be that you only have 1 cluster in your 3.5 environment ?

In that case Get-Cluster won't return an array and you won't have the Count property.

You can do

(Get-Cluster | Measure-Object).Count


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

View solution in original post

Reply
0 Kudos
8 Replies
LucD
Leadership
Leadership
Jump to solution

This should work on 3.5 and vSphere.

Could it be that you only have 1 cluster in your 3.5 environment ?

In that case Get-Cluster won't return an array and you won't have the Count property.

You can do

(Get-Cluster | Measure-Object).Count


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

Reply
0 Kudos
alanrenouf
VMware Employee
VMware Employee
Jump to solution

You can also force it to be an array:

$cluster = @{get-cluster}
$cluster.count

If you found this information useful, please consider awarding points for Correct or Helpful.

Alan Renouf

http://virtu-al.net

Blog: http://virtu-al.net Twitter: http://twitter.com/alanrenouf Co-author of the PowerCLI Book: http://powerclibook.com
LucD
Leadership
Leadership
Jump to solution

Please ignore, original text removed.


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

Reply
0 Kudos
a2alpha
Expert
Expert
Jump to solution

$ESXhost = get-vmhost <host> | get-view

$ESXHost.config.firewall.defaultPolicy.outgoingBlocked

When I run the esxcfg-firewall -allowOutgoing, the above still yields a true response. Is there a way to update it or am I querying the wrong part.

Thanks for the cluster part, works fine now.

Dan

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

The properties of the variable $ESXHost are not automatically updated.

You can force a refresh with

$ESXHost.UpdateViewData()


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

Reply
0 Kudos
a2alpha
Expert
Expert
Jump to solution

Thanks for that, although it still gives a true response. Looking at the name though it looks like it is for the default policy rather than the current status.

Is there a way of querying whether the firewall has been set to allowOutgoing and allowIncoming?

Thanks,

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Afaik there is no specific method to query that info.

The HostFirewallDefaultPolicy object, in which you find the incomingBlocked and outgoingBlocked properties, defines the actions the FW will take for all traffic for which there is no specific rule.

The FW first checks the rules.

If there is no rule that covers that specific type of traffic, the FW takes the default action.


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

Reply
0 Kudos
a2alpha
Expert
Expert
Jump to solution

Thanks for all your help and thanks for the info.

Dan

Reply
0 Kudos