0

I wrote a small Forms GUI in Powershell and in there I have a combobox with emails of users from an AD. Now I got an event on SelectedIndexChanged where I want to display more informations about the selected user in a label. Since i have a unique email as a filter there's always just one returned object with Get-ADUser.

My problem is that Get-ADUser returns an array of strings when i use select cn and even with Out-String it returns a string with the formatting of a returned array.

I don't want to manually remove the @{cn=} when i get the returned string. So is there a more effective way to get JUST the value of the returned string array?

This is what I tried:

$label_name.Text = Get-ADUser -Properties mail -Filter {mail -like $comboBox_User.Text} | select cn | Out-String

the returned string looks like this:


cn
-
foo (returned name)
 

the return i was expecting:

foo
Moyo
  • 3
  • 4

1 Answers1

1

Your query is missing the cn property so make sure that's included in Get-ADUser as it's not returned by default. Expand the CN property. You don't need | Out-String with that.

$label_name.Text = Get-ADUser -Properties mail,cn -Filter {mail -like $comboBox_User.Text} | Select-Object -expand cn

Robin
  • 1,602
  • 3
  • 16
  • 24