Tags

Howto (51) Free Software (35) Powershell (33) Windows Server (23) AD (16) Hyper-V (16) Exchange (13) Office (13) Group Policy (10) Windows Server 2012 (9) Scripts (7) Symantec BE (5) Windows 8 (5) Cisco (4) TMG (4) Terminal Server (4) Cluster (3) HP (3) RDS (3) UAG (3) Citrix (2) DC (2) DNS (2) IE10 (2) OpenID (2) PKI (2) SCVMM (2) Windows Live (2) iLO (2) Backup (1) DPM (1) Fileserver (1) IE (1) SQL; DPM (1) Security (1) Sharepoint (1) Switch (1) VMWare (1) Veeam (1)

dinsdag 11 december 2012

Export AD enabled users to csv with batch file

I use a batch file to import the Active Directory module and execute a powershell script:
 
REM BEGIN BATCH FILE >>>
@echo off
c:
cd\
cd temp
echo Creating an export of enabled AD users who have an EmployeeID to a UTF8 encoded CSV file
C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe -Command Import-Module ActiveDirectory;"c:\temp\exportadusers.ps1"
echo done
exit
REM END BATCH FILE <<<
 
Thanks to get-date you can create a different export file everytime the script is executed.
Since AD responses are in UTF-8 character encoding for LDAP it is the best encoding you can use when exporting.
Default export is ASCII. When exporting in ASCII certain characters like ë will return as a question mark “?”
 
# BEGIN POWERSHELL SCRIPT >>>
$a = get-date -Format "yyyyMMddHHmm"
Get-ADUser -filter * -Properties * -SearchBase "OU=Sales,DC=domain,DC=Local" | where {$_.EmployeeID -ne $null -and $_.Enabled -ne $false} | Select-Object EmployeeID,UserPrincipalName,DisplayName,mail | sort EmployeeID | Export-Csv c:\temp\exportADusers$a.csv -encoding "utf8"
# END POWERSHELL SCRIPT <<<
 
 
 

Geen opmerkingen:

Een reactie posten