Forum Discussion

Mats Warnolf's avatar
Mats Warnolf
Brass Contributor
May 03, 2017

expanding a System.Collections.Generic.List[string]

Im using the following code to add properties to an object

 

$ten = Get-MsolCompanyInformation -TenantId $tenantItem
$objTenantData = New-Object -TypeName system.object
$objTenantData | Add-Member -Type NoteProperty -Name AuthorizedServiceInstances -value $ten.AuthorizedServiceInstances

The problem is that some of the properties of the MsolCompanyInformation are lists (System.Collections.Generic.List[string])

 

I need help to get the contents of that list into  $objTenantData as text.

 

Can you help me?

 

 

/Mats

 

 

 

 

  • I am assuming that the Add-member line is just one of many you want to add to the $objTennantData object and that you want the string array added as a single value (let me know if these assumptions are incorrect)

    If so, for any properties that are arrays use the following:
    $objTenantData | Add-Member -Type NoteProperty -Name AuthorizedServiceInstances -value ($ten.AuthorizedServiceInstances -join ' ')

    Note: You can put other symbols in the ' ' after join and that is what will separate each value in the new string.
  • I am assuming that the Add-member line is just one of many you want to add to the $objTennantData object and that you want the string array added as a single value (let me know if these assumptions are incorrect)

    If so, for any properties that are arrays use the following:
    $objTenantData | Add-Member -Type NoteProperty -Name AuthorizedServiceInstances -value ($ten.AuthorizedServiceInstances -join ' ')

    Note: You can put other symbols in the ' ' after join and that is what will separate each value in the new string.

Resources