AnsweredAssumed Answered

How to use Array content in a PSObject as drop down values

Question asked by dnnsrnhrdt on Mar 3, 2019
Latest reply on Jun 19, 2019 by dnnsrnhrdt

Hi @ll,

 

Probably the solution is again very simple, nevertheless the problem presents me with a challenge.

Based of some code from oskar.frolin2 and the PSObject part from the AP PSWS"Get compliance info", I use AP to collect information from SLM, no big deal!

 

function GetSLMApplicationDetails {

param(
    $applicationid
)

    #region Settings
        $SLMAccountName = Get-APSetting "SLMApiAccountName"
        $SLMServerName  = Get-APSetting "SLMUri"
        $SLMCustomerId  = Get-APSetting "SLMCustomerId"
        $APPortalBaseAddress  = Get-APSetting "PortalBaseAddress"
        $apiUserAccount = Get-ServiceAccount -Name $SLMAccountName
    #endregion

    #region Credential and base uri to Snow License Manager
        $securePassword = ConvertTo-SecureString $($apiUserAccount.Password) -AsPlainText -Force
        $credential = New-Object Management.Automation.PSCredential ($($apiUserAccount.AccountName), $securePassword)
        $apiUri = "$SLMServerName/api/Customers/$SLMCustomerId/applications"
    #endregion

    $invokeUrl = "$apiUri/$applicationId/?" + '$format=json'

    #region Get compliance details from Snow License Manager
    $application = Invoke-RestMethod -Uri $invokeUrl -Credential $credential


$ApplicationName                                          = $application.body.Name                                        
$ApplicationMetric                                        = $application.body.Metric

    switch ($ApplicationMetric) {
   "Installations" {$ApplicationMetric = "Installations"; break}
   "TotalUsers" {$ApplicationMetric = "Users"; break}
   "TotalCores" {$ApplicationMetric = "Number of processor cores"; break}
   "TotalProcessors" {$ApplicationMetric = "Number of processors"; break}
   default {$ApplicationMetric = "Installations"; break}
   }
[...]      

                                   
#License specific information
$LicenseAssignment = "Organisation","User","Site","Computer/datacenter"

    # return object to pipeline
    New-Object -TypeName psobject -Property @{
        "ApplicationName"           = $ApplicationName
        "ApplicationMetric"         = $ApplicationMetric
        "LicenseAssignment" = $LicenseAssignment
    }
}

Running the code in PS the output looks good to me

 

Adding the PSWS to my parameters (e.g.  "ApplicationName" and "LicenseAssignment")

 

 

ApplicationName delivers the right content, but LicenseAgreement only shows me a "System.Object[]"

 

I also tried it with the -join parameter in the psobject, but this didn't worked not as expected. Formated the content into one line instead of individual lines for the drop down

"LicenseAssignment" = $LicenseAssignment -join "`r`n"

 

 

The goal is to use a single PS WS that allows me to provide different information and not have to build an extra service for each field. Has any of you experienced how to correctly output arrays in a PSObject in AP?

 

Thanks and Best,

Dennis

Outcomes