Hi,
try to find user email
i have user computer name, from ad i can get user computer name:
$compname = “Test1”
$compuser = Get-ADComputer -Filter (“Name -Like ‘$compname’”) -Property * |
Select Description
$compuser
now i have First and Last Name,
How i can find email address in AD?
i try, and now i know why its not working and i need help
when i get Description from computer record, i have FirstName and LastName,
but in user account Display name set LastName, FirstName
i try : Get-ADUser -Filter {Name -like “%$compname%”} -Properties Mail | Format-List
You should be able to get the same results with something like this:
get-aduser -identity USER1 -properties givenname, surname, mail | select givenname, surname, mail
Are you trying to get username or a computer name with this? %compname%…get-aduser will only retrieve users in AD
Get-ADUser -Filter {Name -like “%$compname%”} -Properties Mail | Format-List
thx, for your exp,
this in what i try to do
i have computername - Test1
i can get computer description( and this is user name),then i try find email for this user
or how i can split Tom Jhons
exp:
$compname = “Test1”
$compuser = Get-ADComputer -Filter (“Name -Like ‘$compname’”) -Property * |
Select Description
$compuser
This is a basic, untested example. You need to get the description, split at the spaces and then get the parts of the name:
$Description = Get-ADComputer -Filter "Name -eq 'Computer123'" -Properties Description | Select -ExpandProperty Description
if ($Description) {
$arrDesc = $Description -split " "
$givenname = $arrDesc[0]
$surname = $arrDesc[1]
#Keep in mind a search can have more than one result. This example assumes there is on result
$email = Get-ADUser -Filter "givenName -eq '$givenname' -and surName -eq '$surname'" -Properties mail | Select -ExpandProperty mail
}