Powershell Help

Posted on 2012-08-24
Last Modified: 2012-08-24
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!
Question by:Will Szymkowski
    LVL 37

    Accepted Solution


    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

    LVL 53

    Author Comment

    by:Will Szymkowski
    Thanks for the response. Worked like a charm.


    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Join & Write a Comment

    I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
    Set OWA language and time zone in Exchange for individuals, all users or per database.
    This tutorial will walk an individual through configuring a drive on a Windows Server 2008 to perform shadow copies in order to quickly recover deleted files and folders. Click on Start and then select Computer to view the available drives on the se…
    This tutorial will show how to configure a new Backup Exec 2012 server and move an existing database to that server with the use of the BEUtility. Install Backup Exec 2012 on the new server and apply all of the latest hotfixes and service packs. The…

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now