General Discussion

PSTK: Select specific property value

tyrone_owen_1
1,882 Views

Hi, hope you can help.

 

I'm using REST API to pull back cluster properties in order to output to an Excel spreadsheet.

 

# Set URI variable for retrieving properties
[String]$Uri = "https://$HostIP/api/cluster?fields=**&return_records=true&return_timeout=15"

# Trigger REST API call and store in a variable
$UriResponse = Invoke-RestMethod -Method GET -Uri $Uri -Headers $Headers -ErrorAction Stop

# Select specific properties
$ObjectProperties = $UriResponse | Select-Object -Property name,location,version

 

Looking at the $ObjectProperties variable, the 'name' and 'location' properties are in a format that I m happy with, however the 'version' property has a series of properties bundled into a hash table.

 

PS C:\windows\system32> $ObjectProperties

name         location    version                                                                                                                          
----         --------    -------                                                                                                                          
cluster_name room21      @{full=NetApp Release 9.8P3: Sat Mar 27 08:43:48 UTC 2021; generation=9; major=8; minor=0; name=h3bspprdm1; location=Cabinet P49}

 

I'd like to have the output in this format:

 

name         location    version                                                                                                                          
----         --------    -------                                                                                                                          
cluster_name room21      NetApp Release 9.8P3: Sat Mar 27 08:43:48 UTC 2021

 

Can you help please?

1 ACCEPTED SOLUTION

jcolonfzenpr
1,870 Views

Hi,

 

You can transform the version variable:

 

 

$ObjectProperties = $UriResponse | Select-Object -Property name,location,@{Label = "version"; expression = {$_.version.full}}

 

 

Example:

 

$ObjectProperties = $UriResponse | Select-Object -Property name,location,@{Label = "version"; expression = {$_.version.full}}
PS /home/rebelinux> 

PS /home/rebelinux> $ObjectProperties                                                                      
                                                    
                                                                                                                
name       location version    
----       -------- -------                                  
ONTAP-EDGE HomeLAb  NetApp Release 9.5P17: Wed May 12 20:42:52 UTC 2021
                
PS /home/rebelinux> 

 

 

Hope this helps!

Jonathan Colón | Blog | Linkedin

View solution in original post

2 REPLIES 2

jcolonfzenpr
1,871 Views

Hi,

 

You can transform the version variable:

 

 

$ObjectProperties = $UriResponse | Select-Object -Property name,location,@{Label = "version"; expression = {$_.version.full}}

 

 

Example:

 

$ObjectProperties = $UriResponse | Select-Object -Property name,location,@{Label = "version"; expression = {$_.version.full}}
PS /home/rebelinux> 

PS /home/rebelinux> $ObjectProperties                                                                      
                                                    
                                                                                                                
name       location version    
----       -------- -------                                  
ONTAP-EDGE HomeLAb  NetApp Release 9.5P17: Wed May 12 20:42:52 UTC 2021
                
PS /home/rebelinux> 

 

 

Hope this helps!

Jonathan Colón | Blog | Linkedin

tyrone_owen_1
1,828 Views

Thanks very much Jonathan, worked a treat

Public