Splitting and filtering strings

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

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 = ‘;’

Thanks for that Rob, will check that out