Solved

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

Posted on 2015-01-30
3
117 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 40

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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
In this previous article (https://oddytee.wordpress.com/2016/05/05/provision-new-office-365-user-and-mailbox-from-exchange-hybrid-via-powershell/), we made basic license assignments to users in O365. When I say basic, the method is the simplest way …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

808 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