Author Posts

October 20, 2015 at 3:13 pm

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!


October 20, 2015 at 6:30 pm

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

For example instead of:



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

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

October 20, 2015 at 9:59 pm

That worked great! Thank you!