Author Posts

May 14, 2013 at 10:51 am

I need some help!

I have a one-liner that extracts specific user data from AD and saves it in to a CSV file.  One of those attributes is proxyAddresses from which I only need to extract the primary SMTP and X400 addresses i.e. where X400 and SMTP are in uppercase. The addresses are separated in the string by a space which needs replacing by a semi-colon.  Any idea how I can achieve this?

get-ADobject -filter 'displayname -like "XYZ*" -and mail -like "*@*"' -properties sn,givenName,DisplayName,title,mail,physicalDeliveryOfficeName,telephoneNumber,facsimileTelephoneNumber,proxyAddresses |
Select-Object sn,givenName,displayName,physicalDeliveryOfficeName,telephoneNumber,facsimileTelephoneNumber,title,mail,BuildingCode,@{name="Proxies";expression={[string]$_.proxyAddresses}} |
ConvertTo-Csv -NoTypeInformation | foreach {$_ -replace '"', ''} | out-file $exportFile

May 14, 2013 at 1:55 pm

You're casting it to [string] to unroll the array, and that's separating the members with a space. Powershell has an automatic variable called $OFS (for Output Field Separator) that determines what separator character(s) will be used when you do that. The default value is a space. If you change that to a semi-colon before you run that script, it will use that instead of the space.

$OFS = ';'

May 15, 2013 at 3:27 am

Thanks for that Rob, will check that out