0

I am running a command that queries my storage array for a list of items. The output gets stored as follows

$ls_xtrem_clusters = Get-XtremClusters
write-host $ls_xtrem_clusters

This results in the output

@{href=https://192.168.1.1/api/json/v2/types/clusters/1; name=cluster1}

What I am trying to do is get a list of the names only. So if there were 3 clusters, I want an array that contains the values cluster1, cluster2, cluster3. This is dynamic content, so I need to be able to extract the data from the values returned by the Get-XtremClusters command.

I tried this

$ls_xtrem_clusters = Get-XtremClusters
$ls_xtrem_cluster | select-object name | %{write-host $_}

Which gave me

@{name=cluster1}

So my question is, how do I extract cluster1 (or if multiple exist cluster1, cluster2, cluster3) and put it in an array?

1
  • In PowerShell 3 or 4, you can possibly do (Get-XtremClusters).Name Commented Oct 16, 2015 at 21:47

1 Answer 1

1

You really don't need the Write-Host bit. What you do need is the -ExpandProperty argument for Select-Object. Try this out:

$ls_xtrem_clusters = Get-XtremClusters
$ls_xtrem_cluster | select-object -Expand name
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, that worked I used this though $my_clusters = $ls_xtrem_clusters | select-object -Expand name foreach ($i in $my_clusters){write-host $i} I am using it that way since I will be adding a numeric value to each entry and created a selectable list. Now I just have to work that bit out.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.