PowerShell to get CSV export of Active Directory


A quick note on a script I threw together on exporting user information from Active Directory. The old script I was using stopped working, so I needed to rework it. Here is what I came up with:

Import-Module ActiveDirectory

$path = Split-Path -parent "C:\Users\[user]\Downloads\*.*"
$LogDate = get-date -f yyyyMMddhhmm
$csvfile = $path + "\ALLADUsers_$logDate.csv"

Get-ADUser -Filter "Enabled -eq 'TRUE' -and employeeType -eq 'Employee'" -Properties displayname, employeeType, enabled, givenname, sn, manager, mail, streetaddress, city, st, postalcode, co, telephonenumber, mobile, ipphone, homephone, extensionattribute2, extensionattribute3, extensionattribute4,
company, department, extensionattribute1, title, physicaldeliveryofficename | Select-Object displayname, employeeType, enabled, givenname, sn, mail, streetaddress, city, st, postalcode, co, telephonenumber, mobile, ipphone, homephone, extensionattribute2, extensionattribute3, extensionattribute4, company, department, extensionattribute1, title, physicaldeliveryofficename, @{Label = "Manager";Expression = {%{(Get-AdUser $_.Manager -Properties DisplayName).DisplayName}}} | export-csv $csvfile -NoTypeInformation

Sources


Share on Google Plus

About Tom DeMeulenaere

Highly accomplished information technology professional with extensive knowledge in System Center Configuration Manager, Windows Server, SharePoint, and Office 365.
    Blogger Comment

0 comments:

Post a Comment

Note: Only a member of this blog may post a comment.