1

I'm having an issue with following piece of code:

$NodeList = (get-scvmhostcluster ClusterName| where-object {$_.nodes.fullyqualifieddomainname -ne "Host001.Domain.Tld"}).nodes.fullyqualifieddomainname

Normally this should filter from the list of Hosts the "Host001.Domain.tld" out of the list. (Host001 up to Host014 is what this list normally generates, unfiltered).

However, when running the script block and seeing whats in the $NodeList variable I get every single object as if the filter was not applied.

I've been trying to debug this for a few hours now but to no avail.

Anyone able to point out my wrongdoings ?

Regards,

5
  • If you executeget-scvmhostcluster ClusterName| foreach-object {$_.nodes.fullyqualifieddomainname} do you get any values? Commented Feb 9, 2015 at 10:36
  • Yes, I get all the FQDN's of the Host's in the Cluster. Commented Feb 9, 2015 at 10:59
  • is fullyqualifieddomainname a string? if you put a breakpoint at the where-object block, and check $_.nodes.fullyqualifieddomainname.GetType() what do you get? Commented Feb 9, 2015 at 11:25
  • I also wonder if there is whitespace on the string that is causing the comparison to fail. Perhaps you will get results from where-object {$_.nodes.fullyqualifieddomainname -notlike "*Host001.Domain.Tld*"} Commented Feb 9, 2015 at 14:09
  • Matt, no whitespaces (your codeblock didn't change anything) Micky, String objects yes Commented Feb 9, 2015 at 14:41

1 Answer 1

1

Get-SCVMHostCluster ClusterName returns a single cluster object.

When you pipe it to Where-Object, you have the following:

  1. $_.Nodes is a collection of objects with a fullyqualifieddomainname property of type string
  2. $_.Nodes.fullyqualifieddomainname is therefore a collection of collections of strings

Where-Object will only collapse the first "level" of collections, it won't go deeper - and therefore your filter will never match anything, a collection of string arrays will never match the lone string you're comparing against.

Here is what I would do, collapsing the first level by selecting the Nodes property (broken into statements for readability, feel free to pipe it in one statement):

$Nodes = Get-SCVMHostCluster ClusterName|Select-Object -ExpandProperty Nodes
$NodeList = $Nodes |Where-Object {$_.fullyqualifieddomainname -ne "Host001.domain.tld"}|Select-Object -ExpandProperty fullyqualifieddomainname
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.