Export all users in AD

This could be very helpful for reports, where management loves reports 😛

$users = @()
$pathtosave1 = "Path to save.csv"
Add-Content -Path $pathtosave1 -Value '"Fist Name","Last Name","SAM Name","Email Address","Enabled"'

$users += Get-ADUser -Filter * -SearchBase "give the base of the Domain" -Properties * | select givenname,surname,samaccountname,mail,enabled

foreach($user in $users)
{
 Add-Content -Path $pathtosave1 -value ($user.givenname+","+$user.surname+","+$user.samaccountname+","+$user.mail+","+$user.enabled)
} 

Published by iamfazul

Author of the site

Leave a comment