• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 682
  • Last Modified:

Powershell Help

Hello Experts,

We currently have a list of users in a CSV file and they have only provided me with the GivenName and Surname. They would like me to do a search in AD to see if the account exists, and if it does provide the sAMAccountName and Email Address (if one). If the account does not exist write-host Account not found.

I typically use the sAMAccountName with a Write-host saying if the account exists or not but they are requiring a little more information and providing me with different attributes.

Any help would be appreciated!
0
Will Szymkowski
Asked:
Will Szymkowski
1 Solution
 
Jamie McKillopCommented:
Hello,

Try this:

Import-Csv c:\import.csv | % {
	$Firstname = $_.givenname
	$Lastname = $_.surname
	$user = Get-User -Filter {firstname -eq $firstname -and lastname -eq $lastname}
	foreach ($item in $user) {	
		if ($item -eq $null) {
			Write-Host "$($firstname) $($lastname) Not Found"
		} else {
			Write-Host "$($item.samaccountname) $($item.windowsemailaddress)"
		}
	}
}

Open in new window


JJ
0
 
Will SzymkowskiSenior Solution ArchitectAuthor Commented:
Thanks for the response. Worked like a charm.

:-D
0

Featured Post

A Cyber Security RX to Protect Your Organization

Join us on December 13th for a webinar to learn how medical providers can defend against malware with a cyber security "Rx" that supports a healthy technology adoption plan for every healthcare organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now