AD Powershell Command

RTmarcRTmarc Member Posts: 1,082 ■■■□□□□□□□
Ok, here's what I'm trying to do. I'm attempting to pull a list of all disabled users from AD. I've got the script working but I'm having issues trimming down exactly what I need.

Here's my script:
Search-ADAccount -AccountDisabled -UsersOnly | FT Name,SamAccountName -A

I'd like to trim this down to just show me the user ID. I don't care about the name because I'm going to be taking the user IDs and pumping them into another application. When I try to run this:
Search-ADAccount -AccountDisabled -UsersOnly | SamAccountName -A

the command fails.

Any ideas? And, yes I'm doing this in PowerShell for a reason.

Comments

  • RTmarcRTmarc Member Posts: 1,082 ■■■□□□□□□□
    Figured it out. Here is the code that works:
    Seach-ADAccount -AccountDisabled -UsersOnly | Get-ADUser -Properties SamAccountName | Select SamAccountName | Sort-Object SamAccountName
    

    If there is a more efficient way to do this command, I'm interested in hearing what you have.
  • RobertKaucherRobertKaucher A cornfield in OhioMember Posts: 4,299 ■■■■■■■■■■
    RTmarc wrote: »
    Figured it out. Here is the code that works:
    Seach-ADAccount -AccountDisabled -UsersOnly | Get-ADUser -Properties SamAccountName | Select SamAccountName | Sort-Object SamAccountName
    

    If there is a more efficient way to do this command, I'm interested in hearing what you have.
    At a glance the code looks fine to me.

    Have you looked at the Quest Software AD Commandlets? These are from the same company that created the PowerGUI Script Editor.
Sign In or Register to comment.