Forum Discussion

StefanoC66's avatar
StefanoC66
Iron Contributor
Oct 10, 2024

Multiple @name substitution in one line import

I'm trying to export all the "conditional" attributes from the Get-DynamicDistributionGroup into a csv file

ConditionalCompany : {}
ConditionalStateOrProvince : {}
ConditionalCustomAttribute1 : {}
ConditionalCustomAttribute2 : {}

these attributes are a Microsoft.Exchange.Data.MultiValuedProperty`1[System.String] so to correctly export them to csv we should use the following for each of them 

@{Name="ConditionalCustomAttribute1";Expression={($_.ConditionalCustomAttribute1)}}

@{Name="ConditionalCustomAttribute2";Expression={($_.ConditionalCustomAttribute2)}}

...

I was wondering if there's a way to "expand" the * inside the @{}  instead 
something like 

@{Name="ConditionalAttribute*";Expression={($_.ConditionalAttribute*)}}

  • sdtslmn's avatar
    sdtslmn
    Brass Contributor

    StefanoC66 

     

    $attributes = @("ConditionalCompany", "ConditionalStateOrProvince", "ConditionalCustomAttribute1", "ConditionalCustomAttribute2")
    $dynamicGroup = Get-DynamicDistributionGroup
    
    $properties = $attributes | ForEach-Object { @{Name=$_; Expression={ $_.($_) }} }
    
    $dynamicGroup | Select-Object -Property Name, $properties | Export-Csv -Path "output.csv" -NoTypeInformation

Resources