Solved

Get-ADUser against txt file containing UPNs

Posted on 2016-10-19
1
28 Views
Last Modified: 2016-10-19
I have a txt file with UPNs, is there a way to run a Get-ADUser against that txt file and pull back UserPrincipalName,Enabled,SamAccountName,ObjectClass details via the Active Directory Module in AD, then export results to CSV.
0
Comment
Question by:Christian Hans
1 Comment
 
LVL 39

Accepted Solution

by:
footech earned 500 total points
ID: 41851152
Why get the ObjectClass?  It's always going to be "user".
Anyway, it's a pretty simple script.
Get-Content UPNs.txt | ForEach `
{
    Get-ADUser -Filter { UserPrincipalName -eq $_ } -Properties UserPrincipalName,Enabled,SamAccountName,ObjectClass
} | Select UserPrincipalName,Enabled,SamAccountName,ObjectClass |
 Export-CSV UserInfo.csv -NoTypeInformation

Open in new window

0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
In this article, I am going to show you how to simulate a multi-site Lab environment on a single Hyper-V host. I use this method successfully in my own lab to simulate three fully routed global AD Sites on a Windows 10 Hyper-V host.
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…

776 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