Reputation: 11
I would like to assign SamAccountName
to a variable while I run Get-ADUser
cmdlet in PowerShell, I tried the following command but always return error.
$manager_sam = Get-ADUser -Identity $manager |fl SamAccountName
Upvotes: 1
Views: 503
Reputation: 10764
Assuming that $manager
contains a string that's valid to be passed as -Identity
, you can just use
$manager_sam = (Get-ADUser -Identity $manager).sAMAccountName
Upvotes: 2
Reputation: 58931
Use the Select-Object
instead of the Format-List
cmdlet:
$manager_sam = Get-ADUser -Identity $manager | Select-Object -expand SamAccountName
Upvotes: 3