Solved

PowerShell export to csv. Only quote 1 set in each row

Posted on 2014-04-17
1
539 Views
Last Modified: 2014-04-17
When I'm building a CSV Export it puts quotes around every set of parameters. However, I only want 1 set to have the quotes.
$UserInfo = New-Object System.Object
foreach($user in $MailBoxList)
{
$UserInfo | Add-Member -Type NoteProperty -Name LegacyExchangeDN -Value $user.LegacyExchangeDN
$UserInfo | Add-Member -Type NoteProperty -Name CloudEmailAddress -Value $CloudEmailAddress
$UserInfo | Add-Member -Type NoteProperty -Name OnPremiseEmailAddress -Value 
$user.PrimarySMTPAddress.ToString()

$UserInfo | Add-Member -Type NoteProperty -Name MailboxGUID -Value $user.ExchangeGUID

$Users += $UserInfo

}

$Users | Export-CSV -Delimiter "," -Path ".\cloud.csv" -NoTypeInformation

Open in new window



This code results in this exported CSV: "LegacyExchangeDN","CloudEmailAddress","OnPremiseEmailAddress","MailboxGUID" "/o=MyUnit/ou=This Admin Group (BRBIDOMF87SRQLT)/cn=Recipients/cn=a0dd27c5djd864108cfa61dj37dj56c6-MyLastName, M","mMyLastName@WhereverImFrom.Bob.com","mMyLastName@AnotherDomain.com","687efe5e-4690-110e-86a5-69fr4cdecf7e"

What I'd like is just the first column of data to have double quotes and the rest without: "/o=MyUnit/ou=This Admin Group (BRBIDOMF87SRQLT)/cn=Recipients/cn=a0dd27c5djd864108cfa61dj37dj56c6-MyLastName, M",mMyLastName@WhereverImFrom.Bob.com,mMyLastName@AnotherDomain.com,687efe5e-4690-110e-86a5-69fr4cdecf7e

Any thoughts?
0
Comment
Question by:skipper68
1 Comment
 
LVL 9

Accepted Solution

by:
skipper68 earned 0 total points
ID: 40006579
It just came to me, why don't I just make my own CSV file !

$Outfile = ".\cloud.csv"
'LegacyExchangeDN,CloudEmailAddress,OnPremiseEmailAddress' | Set-Content $Outfile

foreach($user in $MailBoxList)
{
  $Data = @(
             $user.LegacyExchangeDN,
             $CloudEmailAddress,
             $user.PrimarySMTPAddress.ToString()
            )

 '"{0}",{1},{2}' -f $Data | Add-Content $Outfile
}

...and it worked.  I'll leave this question out here for others to find if they have a similar issue.
0

Featured Post

Do email signature updates give you a headache?

Do you feel like you are constantly making changes to email signatures? Are the images not formatting how you want them to? Want high-quality HTML signatures on all devices, including on mobiles and Macs? Then, let Exclaimer solve all your email signature problems today.

Join & Write a Comment

Disabling the Directory Sync Service Account in Office 365 will stop directory synchronization from working.
Local Continuous Replication is a cost effective and quick way of backing up Exchange server data. The following article describes the steps required to configure Local Continuous Replication. Also, the article tells you how to restore from a backup…
In this video we show how to create a Distribution Group in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Recipients >>…
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now