Loading
How to use Array content in a PSObject as drop down values
Hi @ll, Probably the solution is again very simple, nevertheless the problem presents me with a challenge. Based of some code from ‌ 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

  • I've got the problem a little bit under control now. Based on a CSV input file (here you can also use a different source), I can at least fill a drop down list. PowerShell web service function GetOrgStructure { $orgInput = Import-CSV -Delimiter ';' -Path "C:\ImportData\StockReport.csv"   $Object = New-Object PSObject     $orgInput | foreach {           $ = $_ | Add-Member -Type NoteProperty -Name "Organisation" -Value $_.Organisation -Force           $ = $_ | Add-Member -Type NoteProperty -Name "OrganisationID" -Value $_.OrganisationID -Force    $_       }   } CSV Content: Snow AP result Now to the new problem. If you combine a DropDown with a static list, "- SELECT -" always appears at the beginning, but in my case with a PW WS the last element of the CSV is always selected as default value.     Does anyone have an idea how to fix this problem?   I don't think an additional "- SELECT -" entry in the CSV file makes sense Best, Dennis
    Expand Post
    • Community Manager (Flexera Software)

      Hi It could be because you have more than one dropdown item with the same value. You have two Germany and two Norway right? I'm assuming you are setting the OrganisationID  as the value field in the dropdown.
      • Hi ‌, thanks for this tip, I used Organisation_ID instead of OrganisationID. Now it works. Thanks
  • Hi ‌, do you have any idea, how to avoid the "System.Object[]" when using a PowerShell Object to put content into a Snow AP Drop Down? Or do you have any idea how to use PowerShellWebService to fill a DropDown with content. Thanks and Best, Dennis

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