AntiMalware Status

Get a list of users in certain Department from Active Directory with PowerShell

Here is quick PowerShell snippet to get information on how many user we have in Department and then pull the list from Active Directory to CSV file.

  • Get the total number of users in Department called Software Developer
1
2
3
Import-Module Active Directory
$Users = (Get-ADUser -Filter * -Properties Department | Where-Object {$_.Department -ge 'Software Developer'}).count
Write-Host .. We have total $users in Software Developer Department -Foregroundcolor white -Backgroundcolor red

This will show you total number of user in the department

  • Lets export all users from Department called Software Developer into CSV file
1
2
Import-Module Active Directory
Get-ADUser -Filter * -Properties Department | Where-Object {$_.Department -ge 'Dev Ops'} | Select samAccountName,Surname,GivenName | Export-CSV -Path C:\Export\SoftwareDeveloper.csv -NoTypeInformation -Encoding UTF8

Leave a Reply