clockwood
asked on
Powershell: Select AD info and output to email subject displays @{Name=...
I am trying to pull user information from Active Directory and send it in an email.
$Sam = read-host "Enter username:"
$FullDisplayName1 = Get-ADUser $Sam | select-object Name
$MessageSubject = "Information for " + $FullDisplayName1 + " : " + $Sam + ". "
The email sends successfully but the subject looks like:
Information for @{Name=John Smith} : jsmith.
How do I remove the @{Name= from the Name in the subject line
$Sam = read-host "Enter username:"
$FullDisplayName1 = Get-ADUser $Sam | select-object Name
$MessageSubject = "Information for " + $FullDisplayName1 + " : " + $Sam + ". "
The email sends successfully but the subject looks like:
Information for @{Name=John Smith} : jsmith.
How do I remove the @{Name= from the Name in the subject line
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
It will be more like
$MessageSubject = "Information for $($FullDisplayName1.Name) : $Sam."
since the hash table in $FullDisplayName1 does consist only of the single attribute Name ...
$MessageSubject = "Information for $($FullDisplayName1.Name) : $Sam."
since the hash table in $FullDisplayName1 does consist only of the single attribute Name ...
True, didn't spot he'd done select-object Name after the command, however the same principle applies if that was missed off :)
ASKER
That was exactly it! Thank you so much. I will log that away in my PS knowledge.
Thank you