Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 127
  • Last Modified:

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

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
Brucef
Asked:
Brucef
1 Solution
 
footechCommented:
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
 
Jorge OcampoCommented:
Add the following to export to csv

| Export-csv -path c:\disable.csv
0
 
Vaseem MohammedCommented:
In addition to Jorge comment, use "-noTypeInformation" switch at end.
 | Export-csv -path c:\disable.csv -noTypeInformation
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now