0

Im using the Auvik Powershell module and the return of some of the commands have some multi-values in them.

What's the best way to turn this into a single value object.

type   id                 attributes                                            
----   --                 ----------                                            
tenant 53337108651709 @{domainPrefix=50waters; tenantType=client}            
tenant 58897678651709 @{domainPrefix=BillAve; tenantType=client} 

========================================================= Like this======

type   id               domain prefix    tenant type
----    ----                   ----            ------
tenant 58897678651709         BillAve          client
tenant 53337108651709       50waters          client
1
  • 1
    iterate thru the main collection, iterate thru the values stored in the attributes property to build an object with those props added to it, and - finally - send that new object to your new collection. Commented Jun 21, 2020 at 19:56

1 Answer 1

2

There are more methods and you can see some of them in the following code snippet:

'--- Original object'
$objectOrig | Out-Default

'--- Flattened using a `foreach` loop'
$ObjectFlat = foreach ( $line in $objectOrig ) {
    [pscustomobject]@{
        type=$line.type
        id=$line.id
        domainPrefix=$line.attributes.domainPrefix
        tenantType=$line.attributes.tenantType
    }
}
$ObjectFlat | Out-Default

'--- Flattened using calculated properties'
$ObjectFlaX = $objectOrig | Select-Object -Property type, id,
    @{Name='domainPrefix'; Expression={$_.attributes.domainPrefix}},
    @{Name='tenantType'  ; Expression={$_.attributes.tenantType}}
$ObjectFlaX | Out-Default

Output: 62503286.ps1

--- Original object

type               id attributes
----               -- ----------
tenant 53337108651709 @{domainPrefix=50waters; tenantType=client}
tenant 58897678651709 @{domainPrefix=BillAve; tenantType=client}


--- Flattened using a `foreach` loop

type               id domainPrefix tenantType
----               -- ------------ ----------
tenant 53337108651709 50waters     client
tenant 58897678651709 BillAve      client


--- Flattened using calculated properties

type               id domainPrefix tenantType
----               -- ------------ ----------
tenant 53337108651709 50waters     client
tenant 58897678651709 BillAve      client
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.