locked
empty pipe element is npt allowed RRS feed

  • Question

  • i am getting an empty pipe element is not allowed
    here is my script

    $user = get-content -path c:\temp\names.txt
    import-module ActiveDirectory
    foreach($user in $user) {Get-ADPrincipalGroupMembership $user  | select name, @{n='User';e={$user}}}   | export-csv -path "c:\temp\gm.csv" #  -NoTypeInformation

                                ~
    An empty pipe element is not allowed.
        + CategoryInfo          : ParserError: (:) [], ParseException
        + FullyQualifiedErrorId : EmptyPipeElement

    Friday, October 4, 2019 4:57 PM

All replies

  • Edit: And I just noticed. The result of Get-Contents should be assigned to $Users (for example), then use:

    ForEach ($User In $Users)
    And the txt file should contain the sAMAccountNames of users. The Name (RDN) does not uniquely identify users. You can also use SID, GUID, or distinguishedNames, but sAMAccountName (pre-Windows 2000 logon name in ADUC) is more convenient.


    Richard Mueller - MVP Enterprise Mobility (Identity and Access)





    • Proposed as answer by jrv Friday, October 4, 2019 5:23 PM
    • Unproposed as answer by jrv Friday, October 4, 2019 5:23 PM
    • Edited by Richard MuellerMVP Friday, October 4, 2019 5:36 PM Corrected
    Friday, October 4, 2019 5:13 PM
  • After the pipe use:

    $_.User

    instead of $User.

    Edit: And I just noticed. The result of Get-Contents should be assigned to $Users (for example), then use:

    ForEach ($User In $Users)
    And the txt file should contain the sAMAccountNames of users. The Name (RDN) does not uniquely identify users. You can also use SID, GUID, or distinguishedNames, but sAMAccountName (pre-Windows 2000 logon name in ADUC) is more convenient.


    Richard Mueller - MVP Enterprise Mobility (Identity and Access)




    Richard - look at your answer.

    You cannot use $_.User with Get-Content.

    Drop that suggestion and the answer is correct.



    \_(ツ)_/

    Friday, October 4, 2019 5:24 PM
  • You can't pipe from foreach () anyway.  It's a common trip up.

    $users = get-content -path names.txt
    & {
      foreach($user in $users) {
        Get-ADPrincipalGroupMembership $user | select name, @{n='User';e={$user}}
      }
    } | export-csv -path gm.csv

    Friday, October 4, 2019 5:40 PM
  • Hi,

    Was your issue resolved?

    If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.

    If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.

    If no, please reply and tell us the current situation in order to provide further help.

    Best Regards,

    Lee


    Just do it.

    Monday, October 7, 2019 5:49 AM