GET-ADUSER output issue

Run this command

$sname = get-aduser $sam -properties * | select surname

Results is



This is an object surname ______ smith how to output just smith?

I need to feed this to another command and the surname ____ give the command a problem.


To get the string, you can use -ExpandProperty so that $sname = smith:

$sname = get-aduser $sam -properties * | select -ExpandProperty surname

Probably the most common powershell question.

That worked great

Thank you


This can be marked resolved


Or reference the property:

(get-aduser user1 | select Surname).Surname
(get-aduser user1).surname
get-aduser | % surname