Skip to content

Instantly share code, notes, and snippets.

@JFFail
Created June 1, 2019 21:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save JFFail/6dd9acb0020845a905eeda8fbc8de1a7 to your computer and use it in GitHub Desktop.
Save JFFail/6dd9acb0020845a905eeda8fbc8de1a7 to your computer and use it in GitHub Desktop.
Sample of getting required properties from an AD object and storing a multi-value attribute properly in a .csv file.
# Get the objects with the required attributes and storing proxyAddresses properly in the .csv file.
Get-ADObject -Filter { objectClass -eq "contact" } -Server myserver.mydomain.net -SearchBase "OU=Contacts,DC=mydomain,DC=net" -SearchScope OneLevel -Properties name,givenName,sn,displayName,telephoneNumber,proxyAddresses,targetAddress,mail,mailNickname,company,department,l,physicalDeliveryOfficeName,postalCode,st,streetAddress,title | Select-Object name,givenName,sn,displayName,telephoneNumber,targetAddress,mail,mailNickname,company,department,l,physicalDeliveryOfficeName,postalCode,st,streetAddress,title,@{name="proxyAddresses"; expression={$_.proxyAddresses -join ";"}} | Export-Csv -Path .\sample.csv -Encoding ASCII -Append -NoClobber -NoTypeInformation
# Shows how to then use the proxyAddresses attribute in the future.
$allContacts = Import-Csv -Path .\sample.csv
foreach($singleContact in $allContacts) {
$proxyAddresses = $singleContact.proxyAddresses.Split(";")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment