General Discussion

PSTK: Select specific property value

tyrone_owen_1

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

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

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

tyrone_owen_1

Thanks very much Jonathan, worked a treat

Announcements
NetApp on Discord Image

We're on Discord, are you?

Live Chat, Watch Parties, and More!

Explore Banner

Meet Explore, NetApp’s digital sales platform

Engage digitally throughout the sales process, from product discovery to configuration, and handle all your post-purchase needs.

NetApp Insights to Action
I2A Banner
Public