Solved

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

Posted on 2015-01-30
3
119 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free eBook: Backup on AWS

Everything you need to know about backup and disaster recovery with AWS, for FREE!

Question has a verified solution.

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

A procedure for exporting installed hotfix details of remote computers using powershell
My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

738 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