?
Solved

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

Posted on 2014-04-17
1
Medium Priority
?
553 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In previous parts of this Nano Server deployment series, we learned how to create, deploy and configure Nano Server as a Hyper-V host. In this part, we will look for a clustering option. We will create a Hyper-V cluster of 3 Nano Server host nodes w…
My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
In this video we show how to create a Contact 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 >> Contact ta…
To show how to generate a certificate request 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 Servers >> Certificates…

762 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