none
Script Error [Get-ADGroupMember] RRS feed

  • Question

  • Im running the following script to get AD member List:

    ===============

    $groups = Get-Content C:\temp\grouplist.txt
    $resultsarray =@()
    foreach ($group in $groups) {
        $resultsarray += Get-ADGroupMember -Id $group | select @{Expression={$group};Label="Group Name"},samaccountname,name
    }
    $resultsarray| Export-csv -path C:\temp\Member_List.csv -notypeinformation

    ============

    It gives me result, but also errors like below:

    Get-ADGroupMember : Cannot validate argument on parameter 'Identity'. The Identity property on the argument is null or
    empty.
    At C:\temp\Get_Group_Members_.ps1:4 char:44
    +     $resultsarray += Get-ADGroupMember -Id $group | select @{Expressi ...
    +                                            ~~~~~~
        + CategoryInfo          : InvalidData: (:) [Get-ADGroupMember], ParameterBindingValidationException
        + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.ActiveDirectory.Management.Commands.GetADGrou
       pMember

    ========

    How can it be fixed.

    Thanks

    Kris V --new to PS


    kris vemulaalli

    • Moved by Bill_Stewart Saturday, June 24, 2017 6:25 PM This is not "fix my cargo-cult guesswork script for me" forum
    Tuesday, April 25, 2017 8:43 PM

All replies

  •  $resultsarray += Get-ADGroupMember $group

    You cannot have any blank lines in your file.


    \_(ツ)_/

    Tuesday, April 25, 2017 9:19 PM
  • This would be cleaner an will skip blank lines.

    Get-Content C:\temp\grouplist.txt -PipelineVariable group | 
    	Get-ADGroupMember -Identity $group | 
    	Select-Object @{ n = 'Group'; e = { $group } }, samaccountname |
    	Export-csv C:\temp\Member_List.csv -notypeinformation


    \_(ツ)_/

    Tuesday, April 25, 2017 9:24 PM