• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 562
  • Last Modified:

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

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
skipper68
Asked:
skipper68
1 Solution
 
skipper68Author Commented:
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

What Security Threats Are We Predicting for 2018?

Cryptocurrency, IoT botnets, MFA, and more! Hackers are already planning their next big attacks for 2018. Learn what you might face, and how to defend against it with our 2018 security predictions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now