Skip to content

Instantly share code, notes, and snippets.

@kars85
Last active March 24, 2020 20:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kars85/2a69bfe8b12c1adf280cd05ffacbc37c to your computer and use it in GitHub Desktop.
Save kars85/2a69bfe8b12c1adf280cd05ffacbc37c to your computer and use it in GitHub Desktop.
$destinationCSV = "C:\Temp\export.csv"
'OU=Users, OU=redacted1, OU=blue, OU=tree, OU=oranges, OU=Agencies, DC=business, DC=net', 'OU=Users,OU=redacted2,OU=brown,OU=stick,OU=oranges,OU=Agencies,DC=business,DC=net', 'OU=Users,OU=redacted3,OU=5030,OU=leaf,OU=grapes,OU=Agencies,DC=business,DC=net' | `
ForEach-Object {
Get-ADUser -SearchBase $_ -filter { Enabled -eq $true } -properties samaccountname, givenname, surname, displayname, usdaeauthID, mail, telephonenumber, title, manager, streetAddress, physicalDeliveryOfficeName, state, postalCode, c, l, description | `
Select-Object samaccountname, givenname, surname, displayname, uauthID, mail, telephonenumber, title, @{ Name = 'manager'; Expression = { (Get-ADUser $_.Manager).Name } }, @{ n = 'StreetAddress'; e = { $_.streetaddress -replace "`n", ", " } }, physicalDeliveryOfficeName, state, postalCode, c, l, description } |`
foreach {
[pscustomobject]@{
MAXPERUSER_STATUS = "ACTIVE"
STATUSDATE = ""
USERID = $_.samaccountname
PASSWORDCHECK = "Redacted!"
PASSWORDINPUT = "Redacted!"
GROUPNAME = ""
FIRSTNAME = $_.givenname
LASTNAME = $_.surname
DISPLAYNAME = $_.displayname
DEFSITE = "ENG"
EMAILPSWD = "0"
INACTIVESITES = "0"
LOGINID = $_.authID
LOCATIONORG = "TEST"
PERSONID = $_.samaccountname
POSTALCODE = $_.postalcode
PRIMARYEMAIL = $_.mail
PRIMARYPHONE = $_.telephonenumber
ADDRESSLINE1 = $_.streetAddress -join ";"
ADDRESSLINE2 = $_.physicalDeliveryOfficeName
ADDRESSLINE3 = ""
BILLTOADDRESS = ""
BIRTHDATE = ""
CALTYPE = ""
CITY = $_.l
COUNTRY = $_.c
COUNTY = ""
DEPARTMENT = $_.description
EMPLOYEETYPE = ""
EXTERNALREFID = ""
HIREDATE = ""
LASTEVALDATE = ""
LOCATION = ""
REGIONDISTRICT = ""
STATEPROVINCE = $_.state
SUPERVISOR = ""
TERMINATIONDATE = ""
TITLE = $_.title
MEMO = ""
PASSWORD = ""
PWEXPIRATION = ""
PWHINTANSWER = ""
PWHINTQUESTION = ""
} | Export-Csv -Delimiter "," $destinationCSV -Append -NoTypeInformation
}
#Add mandatory "header" for MIF to import correctly
$oldCSV = Get-Content $destinationCSV
Set-Content -Path $destinationCSV -Value "EXTSYS1,MXPERUSERInterface,,EN"
Add-Content -Path $destinationCSV -Value $oldCSV
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment