Try our new Certificate Revocation List Check Tool
CRLcheck.exe is a tool developed to verify digital signatures of executable files. It collects files from known paths on your client, checks their signature, and checks Certificate Revocation Lists (CRL) and OCSP download. This helps avoid delays in launching files.
Category published:  Deployment Scripting   Click on the Category button to get more articles regarding that product.

Powershell List and Export Active Directory users UNDER certain OU incl. Homeshare

Posted by admin on 16.10.2021

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


Export all Active Directory attributes under certain OU

Change all READ to your site info as mentioned above

# Import the Active Directory module

Import-Module ActiveDirectory

# Define parameters for retrieving AD users

$ADUserParams = @{

‘Server’ = ‘yourdomaincontroller’

‘Searchbase’ = ‘OU=User,OU=Schweiz,DC=butsch,DC=ch’

‘Searchscope’ = ‘Subtree’

‘Filter’ = ‘*’

‘Properties’ = ‘*’

}

# Define parameters for selecting specific user 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 AD users with specified parameters and select specific properties

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”


 


 Category published:  Deployment Scripting   Click on the Category button to get more articles regarding that product.