List Multiple Attributes within a Powershell Form

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of Daniel Geromini Daniel Geromini 1 year, 3 months ago.

  • Author
    Posts
  • #31069
    Profile photo of Daniel Geromini
    Daniel Geromini
    Participant

    I am trying to list all user accounts with the "info" attribute equal to archived* to a Powershell Form listbox window named $reportBox. I have the cmd below:

    get-aduser -LDAPFilter "(info=archived*)" -SearchBase "OU=Test,DC=Domain,DC=Local" -Properties info | select info,distinguishedname | ForEach-Object {[void] $reportBox.Items.Add($_)}

    This displays the following text in the listbox:

    @{info=Archived; distinguishedname=CN=Test User,OU=Test,DC=Domain,DC=Local}
    @{info=Archived; distinguishedname=CN=Test1 User,OU=Test,DC=Domain,DC=Local}
    @{info=Archived; distinguishedname=CN=Test2 User,OU=Test,DC=Domain,DC=Local}

    I want it to look like:

    Archived CN=Test User,OU=Test,DC=Domain,DC=Local
    Archived CN=Test1 User,OU=Test,DC=Domain,DC=Local
    Archived CN=Test2 User,OU=Test,DC=Domain,DC=Local

    What modifications do I need to make to the command so I get this output in a Powershell Form listbox?

    Thanks for any help!

    Daniel

  • #31070
    Profile photo of Curtis Smith
    Curtis Smith
    Participant

    You need to just make a string out of the values you want in your Add method.

    For example instead of:

    $reportBox.Items.Add($_)

    Do:

    $reportBox.Items.Add("$($_.info) $($_.distinguishedname)")

    get-aduser -LDAPFilter "(info=archived*)" -SearchBase "OU=Test,DC=Domain,DC=Local" -Properties info |
     select info,distinguishedname |
      ForEach-Object {[void] $reportBox.Items.Add("$($_.info) $($_.distinguishedname)")}
    
  • #31074
    Profile photo of Daniel Geromini
    Daniel Geromini
    Participant

    That worked great! Thank you!

You must be logged in to reply to this topic.