Create LDIF files for importing into AD (or other LDAP server)


posted by mpetka
02-21-2013

Downloads: 220
File size: 1.1kB
Views: 1,771

Embed
Create LDIF files for importing into AD (or other LDAP server)
  1. $path = "c:\ldif\$(get-date -Format M.d.yyyy@h.m).ldif"           
  2. New-Item -Path $path -ItemType File -Force 
  3.  
  4. $Users = Get-ADUser -Filter {Enabled -eq "True" -and  msExchAssistantName -like "*"} -Properties DistinguishedName,GivenName,Surname,mail,proxyAddresses,msExchAssistantName 
  5. ForEach ($User In $Users
  6.     
  7.     $AN = $User.msExchAssistantName 
  8.     $Admin = Get-ADUser -Filter {Name -eq $an} -Properties Name,mail 
  9.     $DG = $Admin.mail 
  10.     $PA= $null 
  11.     $DN = $User.DistinguishedName 
  12.     $GN = $User.GivenName 
  13.     $SN = $User.Surname 
  14.     $Mail = $User.mail 
  15.     $Name = $User.sAMAccountname 
  16.     $Addresses = $User.proxyAddresses 
  17.           
  18.      
  19. $value = @" 
  20.  
  21. dn: $DN 
  22. changetype: add 
  23. sn: $SN 
  24. givenName: $GN 
  25. owner: $DG 
  26. mail: $Mail 
  27. "@           
  28. Add-Content -Value $value -Path $path 
  29.     ForEach ($Address In $Addresses
  30.     
  31.         If ($Address -cmatch "smtp:" -and $Address -notmatch "lj.gnf.org"
  32.         
  33.             $PA = $Address 
  34.             $value2 = @" 
  35. proxyAddresses: $PA 
  36. "@           
  37.              
  38.             Add-Content -Value $value2 -Path $path  
  39.         
  40.     
  41.  

I needed to create an LDIF file to import into a LINUX LDAP server that is part of the mail system. Two things are interesting here:

1. Cleaning up proxyAddress to only include secondary smtp addresses (email alias)

2. Finding the email-address for the administrative assistant defined in Exchange. (owner field needed for delegation)

Copyright 2012 PowerShell.com. All rights reserved.