Created
June 1, 2019 21:03
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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