Solved

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

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
Synchronize a new Active Directory domain with an existing Office 365 tenant
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

706 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

18 Experts available now in Live!

Get 1:1 Help Now