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