Powershell: List/Export Active Directory users UNDER certain OU incl. Home share

by butsch 13. December 2016 18:54

Powershell: List/Export Active Directory users UNDER certain OU incl. Home share

Searchbase = distinguishedName

How to find this out:

  • Start Active Directory User and Computers Console
  • Go to the OU you want to export and Right click > Attribute Editor
  • Copy the distinguishedName into the script below behind search base
  • Change your Domain controller behind Server

Searchbase = distinguishedName

 

 

IMPORT all Active Directory attributes under certain OU

Change all READ to your site info as mentioned above

import-module ActiveDirectory

 

$ADUserParams=@{

'Server' = 'yourdomaincontroller'

'Searchbase' = 'OU=User,OU=Schweiz,DC=butsch,DC=ch'

'Searchscope'= 'Subtree'

'Filter' = '*'

'Properties' = '*'

}

 

$SelectParams=@{

'Property' = 'SAMAccountname', 'CN', 'title', 'DisplayName', 'Description', 'EmailAddress', 'mobilephone',@{name='businesscategory';expression={$_.businesscategory -join '; '}}, 'office', 'officephone', 'state', 'streetaddress', 'city', 'employeeID', 'Employeenumber', 'enabled', 'lockedout', 'lastlogondate', 'badpwdcount', 'passwordlastset', 'created','homeDrive','homeDirectory'

}

 

get-aduser @ADUserParams | select-object @SelectParams | export-csv "c:\edv\users.csv"

 

Save Powershell as c:\edv\dump.ps1

Logon on to Domain Controller

Start Powershell

Run .\dump.ps1 from c:\edv folder (Notice the .\ infront of dump.ps1)

 

You will get a COMMA Seperated list like this

#TYPE Selected.Microsoft.ActiveDirectory.Management.ADUser

"SAMAccountname","CN","title","DisplayName","Description","EmailAddress","mobilephone","businesscategory","office","officephone","state","streetaddress","city","employeeID","Employeenumber","enabled","lockedout","lastlogondate","badpwdcount","passwordlastset","created","homeDrive","homeDirectory"

 

Tags:

Scripting

Comments are closed

Werbung von Drittfirmen (Nicht Butsch Informatik):

Werbung von Drittfirmen via Google Adsense: