locked
Help with powershell script to list all the members and attributes of imported dynamic DL list RRS feed

  • Question

  • Hello,

    I'm trying to come up with a script where I can supply a CSV file to import into powershell and then have it check all the members of those DLs plus list the conditions needed for the DL.  In my case I know the conditionals will always be customattribute1, customattribute3 and customattribute4 so it simplifies it a bit but I'm having trouble with the export. 

    The CSV doesn't display the results and I suspect its because the values returned are an array of data.  I'm just not quite knowledgeable enough to know how to code it.  Any help is appreciated. 

    $group = $Null $member = $null $Users = $null $report = $null $person = $null

    $dynDLs = $null

    $dynDLs = import-csv c:\ListofDynDLs.csv $group = get-dynamicdistributiongroup $dynDLs $member = get-recipient -recipientpreviewfilter $group.recipientfilter $Users = New-Object System.Object $Users | Add-Member -type NoteProperty -name Users -value $person $Users | Add-Member -type NoteProperty -name Condition1 -value $group.ConditionalCustomAttribute1 $Users | Add-Member -type NoteProperty -name Condition3 -value $group.ConditionalCustomAttribute3 $Users | Add-Member -type NoteProperty -name Condition4 -value $group.ConditionalCustomAttribute4 $Report += $Users $Report | Export-Csv c:\File.csv


    Tuesday, February 6, 2018 8:44 PM

All replies

  • you need to use foreach loop to go thru all your groups

    The foreach loop should go after:

    $Users = New-Object System.Object

    and to end after:

    $Report += $Users

    Your modified script should look like this:

    $group = $Null
    $member = $null
    $Users = $null
    $report = $null
    $person = $null
    $dynDLs = $null
    $dynDLs = import-csv c:\ListofDynDLs.csv
    $group = get-dynamicdistributiongroup $dynDLs
    $member = get-recipient -recipientpreviewfilter $group.recipientfilter
    
    
    $Users = New-Object System.Object
    
    foreach ($g in $group) {
    
    $Users | Add-Member -type NoteProperty -name Users -value $person
    $Users | Add-Member -type NoteProperty -name Condition1 -value $group.ConditionalCustomAttribute1
    $Users | Add-Member -type NoteProperty -name Condition3 -value $group.ConditionalCustomAttribute3
    $Users | Add-Member -type NoteProperty -name Condition4 -value $group.ConditionalCustomAttribute4
    
    $Report += $Users
    }
    
    $Report | Export-Csv c:\File.csv



    Please click on Propose As Answer or to mark this post as and helpful for other people. This posting is provided AS-IS with no warranties, and confers no rights.


    • Edited by Vlad817263 Tuesday, February 6, 2018 9:30 PM
    Tuesday, February 6, 2018 9:28 PM
  • This is the error I'm receiving:

    Get-DynamicDistributionGroup : Cannot convert 'System.Object[]' to the type 'Microsoft.Exchange.Configuration.Tasks.DynamicGroupIdParameter' required by parameter 'Identity'. Specified 
    method is not supported.
    At line:9 char:43
    + $group = get-dynamicdistributiongroup -id $dynDLs
    +                                           ~~~~~~~
        + CategoryInfo          : InvalidArgument: (:) [Get-DynamicDistributionGroup], ParameterBindingException
        + FullyQualifiedErrorId : CannotConvertArgument,Microsoft.Exchange.Management.RecipientTasks.GetDynamicDistributionGroup
     
    Get-Recipient : Cannot validate argument on parameter 'RecipientPreviewFilter'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
    At line:10 char:49
    + $member = get-recipient -recipientpreviewfilter $group.recipientfilter
    +                                                 ~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidData: (:) [Get-Recipient], ParameterBindingValidationException
        + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.Exchange.Management.RecipientTasks.GetRecipient
     
    Export-Csv : Cannot bind argument to parameter 'InputObject' because it is null.
    At line:25 char:11
    + $Report | Export-Csv c:\scripts\File.csv
    +           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidData: (:) [Export-Csv], ParameterBindingValidationException
        + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.ExportCsvCommand

    Tuesday, February 6, 2018 9:49 PM
  • More like this.  You cannot use an array to get groups:

    import-csv c:\ListofDynDLs.csv |
        ForEach-Object{
            $grp = Get-DynamicDistributionGroup $_
            [pscustomobject]@{
    GroupName = $grp.Name Filter = get-recipient -recipientpreviewfilter $grp.recipientfilter Condition1 = $grp.ConditionalCustomAttribute1 Condition3 = $grp.ConditionalCustomAttribute3 Condition4 = $grp.ConditionalCustomAttribute4 } } | Export-Csv c:\File.csv



    \_(ツ)_/


    Tuesday, February 6, 2018 9:56 PM
  • Returns the following error:

    Get-DynamicDistributionGroup : Cannot bind parameter 'Identity'. Cannot convert value "@{Identity=DLNAMEHERE}" to type "Microsoft.Exchange.Configuration.Tasks.DynamicGroupIdParameter". 
    Error: "Cannot convert the "@{Identity=DLNAMEHERE}" value of type "System.Management.Automation.PSCustomObject" to type 
    "Microsoft.Exchange.Configuration.Tasks.DynamicGroupIdParameter"."
    At line:3 char:45
    +         $grp = Get-DynamicDistributionGroup $_
    +                                             ~~
        + CategoryInfo          : InvalidArgument: (:) [Get-DynamicDistributionGroup], ParameterBindingException
        + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.Exchange.Management.RecipientTasks.GetDynamicDistributionGroup
     
    Get-Recipient : Cannot validate argument on parameter 'RecipientPreviewFilter'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
    At line:6 char:60
    +             Filter = get-recipient -recipientpreviewfilter $grp.recipientfilter
    +                                                            ~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidData: (:) [Get-Recipient], ParameterBindingValidationException
        + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.Exchange.Management.RecipientTasks.GetRecipient

    Wednesday, February 7, 2018 8:31 PM
  • You have to specify the column name in your CSV.

     Get-DynamicDistributionGroup$_.<column name>


    \_(ツ)_/

    Wednesday, February 7, 2018 8:38 PM
  • D'oh that was it but now I'm back to my original issue in that the export doesn't contain the data and i'm guessing tbecause the info is an array.  From the csv file.

    Filter Condition1 Condition3 Condition4
    System.Object[] Microsoft.Exchange.Data.MultiValuedProperty`1[System.String] Microsoft.Exchange.Data.MultiValuedProperty`1[System.String] Microsoft.Exchange.Data.MultiValuedProperty`1[System.String]
    System.Object[] Microsoft.Exchange.Data.MultiValuedProperty`1[System.String] Microsoft.Exchange.Data.MultiValuedProperty`1[System.String] Microsoft.Exchange.Data.MultiValuedProperty`1[System.String]

    Wednesday, February 7, 2018 8:55 PM
  • You will have to extract the components of the returned objects.  For arrays use a join to convert to string.


    \_(ツ)_/

    Wednesday, February 7, 2018 9:03 PM