Solved

How can create a powershell script that will list disabled users and their OU?

Posted on 2015-01-30
3
115 Views
Last Modified: 2015-02-02
I want to be able to create a report using powershell that will list disabled users and the OU their account is in only.  I know how to get just the account name and I can get a report with all of their account and AD information.  But I only need to get their account name and OU.  What is your best suggestion to create a powershell script that will give me these 2 pices of information?

Thank you

David
0
Comment
Question by:Brucef
3 Comments
 
LVL 39

Accepted Solution

by:
footech earned 500 total points
ID: 40580756
The following will work for you, assuming you don't have any OU names that have commas in them.
Search-ADAccount -AccountDisabled -UsersOnly | Select samaccountname,@{n="OU";e={($_.distinguishedname -split ",",2)[-1]}}

Open in new window

0
 
LVL 2

Expert Comment

by:Jorge Ocampo
ID: 40580801
Add the following to export to csv

| Export-csv -path c:\disable.csv
0
 
LVL 12

Expert Comment

by:Vaseem Mohammed
ID: 40582154
In addition to Jorge comment, use "-noTypeInformation" switch at end.
 | Export-csv -path c:\disable.csv -noTypeInformation
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

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…
This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

911 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

23 Experts available now in Live!

Get 1:1 Help Now