locked
Add member off groups to info field ad user object RRS feed

  • Question

  • Hi Guys,

    I have this basic code that reads out the member off groups from an AD object.
    Now I want to add these to the info field of the ad object, but important here is that every entry needs to be on a separate line.


    $C4_UserName_Groups = (Get-ADPrincipalGroupMembership -Identity $C4_UserName).Name
    
    foreach ($C4_UserName_Group in $C4_UserName_Groups){
        $groupstring += "$C4_UserName_Group`n"
    }
    
    $groupstring
    
    Get-ADUser $C4_UserName -Properties info | Set-ADUser -Replace @{info="$groupstring"}

    $groupstring gives the correct output within powershell:

    Domain Users
    GG_ROL_SHP-HelpdeskLvl2
    GROEP - Informatica
    OpenEdge_Escapo
    DG_SHP_SherpaHelpdesk
    DG_SHP_SherpaIedereen
    GG_SPT_PRJ_EVT-bijdragen
    GG_RDS_VIV-RDSUsers
    UG_ACL_RMB_LMTD_SHP
    DL_CTX_PRG_ZNF_ViaCerta-Temse


    But in AD GUI it looks like this:

    Domain Users GG_ROL_SHP-HelpdeskLvl2 GROEP - Informatica OpenEdge_Escapo DG_SHP_SherpaHelpdesk DG_SHP_SherpaIedereen GG_SPT_PRJ_EVT-bijdragen GG_RDS_VIV-RDSUsers UG_ACL_RMB_LMTD_SHP DL_CTX_PRG_ZNF_ViaCerta-Temse

    Any help please :-)

    Thanks

    Sunday, November 11, 2018 2:09 PM

Answers

  • # change this
    foreach ($C4_UserName_Group in $C4_UserName_Groups){
        $groupstring += "$C4_UserName_Group`n"
    }
    
    # to this
    $groupstring = $C4_UserName_Groups -join "`r`n"

    Also ADUC will never show as multiline as it is a single line textbox.  To display multiple lines you will need to create a custom tab in ADUC with  multi-line control.

    To see that there are multiple lines do this:

    Get-Aduser jsmith -prop description

    Most MS utilities will only display the first line in the GUI or will display all line on one line.


    \_(ツ)_/




    • Edited by jrv Sunday, November 11, 2018 2:50 PM
    • Marked as answer by Shane Van Geel Sunday, November 11, 2018 8:48 PM
    Sunday, November 11, 2018 2:40 PM