<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.technet.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Use PowerShell to Work with CSV Formatted Text</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2011/09/23/use-powershell-to-work-with-csv-formatted-text.aspx</link><description>Summary : See how to use Windows PowerShell to create CSV files from formatted and unformatted text.</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>re: Use PowerShell to Work with CSV Formatted Text</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2011/09/23/use-powershell-to-work-with-csv-formatted-text.aspx#3465586</link><pubDate>Wed, 16 Nov 2011 17:17:30 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3465586</guid><dc:creator>Jeffrey S. Patton</dc:creator><description>&lt;p&gt;Ok, so maybe someone can answer this question for me. What is the difference between these two commands? Because the output is COMPLETELY different.&lt;/p&gt;
&lt;p&gt;Export-Csv -InputObject $NewReport -Path .\sample.csv -Force&lt;/p&gt;
&lt;p&gt;$NewReport |Export-Csv -Path .\sample.csv -Force&lt;/p&gt;
&lt;p&gt;The first yields a csv of apparently the object, and the second yields a csv with the actual data in it.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3465586" width="1" height="1"&gt;</description></item><item><title>re: Use PowerShell to Work with CSV Formatted Text</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2011/09/23/use-powershell-to-work-with-csv-formatted-text.aspx#3465133</link><pubDate>Mon, 14 Nov 2011 22:58:23 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3465133</guid><dc:creator>Jeffrey S. Patton</dc:creator><description>&lt;p&gt;Ok, I&amp;#39;ve run into something like this and I&amp;#39;m stumped. Here is what I have, code + output.&lt;/p&gt;
&lt;p&gt;$Events = Get-WinEvent -ErrorAction Stop -FilterHashtable @{LogName=&amp;#39;ForwardedEvents&amp;#39;;ID=4733}&lt;/p&gt;
&lt;p&gt;if ($Events.Count)&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;$Events = $Events[0]&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt;$XMLEvent = [XML]$Events.ToXML()&lt;/p&gt;
&lt;p&gt;$tempReport = $XMLEvent.Event.EventData.Data&lt;/p&gt;
&lt;p&gt;$NewReport = @()&lt;/p&gt;
&lt;p&gt;foreach ($line in $tempReport)&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;[string]$EventField = [string]$Line.Name.ToString()&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;[string]$EventData = [string]$Line.&amp;quot;#text&amp;quot;.ToString()&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;$LineItem = New-Object -TypeName PSObject -Property @{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;EventField = $EventField&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;EventData = $EventData&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;$NewReport += $LineItem&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt;$NewReport&lt;/p&gt;
&lt;p&gt;ConvertTo-Csv -InputObject $NewReport&lt;/p&gt;
&lt;p&gt;EventField &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;EventData &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/p&gt;
&lt;p&gt;---------- &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;--------- &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/p&gt;
&lt;p&gt;MemberName &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;- &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/p&gt;
&lt;p&gt;MemberSid &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; S-1-5-21-1248838550-3875098049-756341321-...&lt;/p&gt;
&lt;p&gt;TargetUserName &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Administrators &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/p&gt;
&lt;p&gt;TargetDomainName &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Builtin &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/p&gt;
&lt;p&gt;TargetSid &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; S-1-5-32-544 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/p&gt;
&lt;p&gt;SubjectUserSid &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;S-1-5-21-1248838550-3875098049-756341321-500&lt;/p&gt;
&lt;p&gt;SubjectUserName &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Administrator &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/p&gt;
&lt;p&gt;SubjectDomainName &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; COMPANY &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/p&gt;
&lt;p&gt;SubjectLogonId &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0x23a98 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/p&gt;
&lt;p&gt;PrivilegeList &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; - &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/p&gt;
&lt;p&gt;#TYPE System.Object[]&lt;/p&gt;
&lt;p&gt;&amp;quot;Count&amp;quot;,&amp;quot;Length&amp;quot;,&amp;quot;LongLength&amp;quot;,&amp;quot;Rank&amp;quot;,&amp;quot;SyncRoot&amp;quot;,&amp;quot;IsReadOnly&amp;quot;,&amp;quot;IsFixedSize&amp;quot;,&amp;quot;IsSynchronized&amp;quot;&lt;/p&gt;
&lt;p&gt;&amp;quot;10&amp;quot;,&amp;quot;10&amp;quot;,&amp;quot;10&amp;quot;,&amp;quot;1&amp;quot;,&amp;quot;System.Object[]&amp;quot;,&amp;quot;False&amp;quot;,&amp;quot;True&amp;quot;,&amp;quot;False&amp;quot;&lt;/p&gt;
&lt;p&gt;Originally I was doing this.&lt;/p&gt;
&lt;p&gt;$tempReport += $XMLEvent.Event.EventData.Data `&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;|Select-Object -Property @{Label=&amp;#39;EventField&amp;#39;;Expression=&amp;quot;Name&amp;quot;}, @{Label=&amp;#39;EventData&amp;#39;;Expression=&amp;quot;#text&amp;quot;}&lt;/p&gt;
&lt;p&gt;I thought perhaps because I was tossing XML data into the array, and then later adding more EventData and EventField items it was cause this problem. This seemed obvious because when I would ConvertTo-CSV the additional field items, they would convert over just fine.&lt;/p&gt;
&lt;p&gt;If anyone could shed light I would really appreciate it.&lt;/p&gt;
&lt;p&gt;Thanks!&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3465133" width="1" height="1"&gt;</description></item><item><title>re: Use PowerShell to Work with CSV Formatted Text</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2011/09/23/use-powershell-to-work-with-csv-formatted-text.aspx#3463752</link><pubDate>Mon, 07 Nov 2011 21:42:01 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3463752</guid><dc:creator>Ed Wilson</dc:creator><description>&lt;p&gt;@Terry E. Dow The problem occurs because the &amp;quot;property&amp;quot; that you are seeing, contains another object that is rather rich. This is not just with Get-Service, it exists on MANY cmdlets, such as Get-Process. The way to view the rich data is to pipeline to Select-Object and use the ExpandProperty parameter to expand the property. You could then pipeline that to ExportCSV if you wish. There are problems with CSV formats because it is essentially two dimensional, and there is not way to handle another object in a property. XML can do this. I am going to write a Hey Scripting Guy blog article about this. See November 15, 2011 article. &lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3463752" width="1" height="1"&gt;</description></item><item><title>re: Use PowerShell to Work with CSV Formatted Text</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2011/09/23/use-powershell-to-work-with-csv-formatted-text.aspx#3463730</link><pubDate>Mon, 07 Nov 2011 19:27:37 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3463730</guid><dc:creator>Terry E Dow</dc:creator><description>&lt;p&gt;What&amp;#39;s the most elegant way to use EXPORT-CSV command to handle mulit-value elements? &amp;nbsp;GET-SERVICE | FORMAT-LIST vs. GET-SERVICE | EXPORT-CSV Service.csv. &amp;nbsp;The latter generates a column called DependentServices with its type (System.ServiceProcess.ServiceController[]) instead of the array values. &amp;nbsp;Yet FORMAT-LIST and practically all other format/export commands expands these. &amp;nbsp;Without writing code specific for this one column from this one command, how can I get EXPORT-CSV to expand array values in general? &amp;nbsp;&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3463730" width="1" height="1"&gt;</description></item><item><title>re: Use PowerShell to Work with CSV Formatted Text</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2011/09/23/use-powershell-to-work-with-csv-formatted-text.aspx#3455700</link><pubDate>Mon, 26 Sep 2011 22:44:33 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3455700</guid><dc:creator>Ed Wilson</dc:creator><description>&lt;p&gt;@camlost, @Craig you are absolutely correct that the -encoding parameter is excellent to use. Keep in mind that Windows PowerShell defaults to unicode, but there are certainly times you need ASCII. For those cases, use -encoding ASCII&lt;/p&gt;
&lt;p&gt;@Q thanks. I am glad you liked the article.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3455700" width="1" height="1"&gt;</description></item><item><title>re: Use PowerShell to Work with CSV Formatted Text</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2011/09/23/use-powershell-to-work-with-csv-formatted-text.aspx#3455356</link><pubDate>Sun, 25 Sep 2011 00:06:34 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3455356</guid><dc:creator>Craig Lussier</dc:creator><description>&lt;p&gt;Ed - Thanks for this article. A lot of folks encounter the issues that you propose a solution for in this post. As indicated by &amp;#39;camlost&amp;#39;, a useful (in my opinion given the appropriate scenario is an important) parameter of Export-CSV cmdlet is the -Encoding parameter. I have encountered many scenarios where this parameter makes all the difference between frustration and success with regards to the expected csv output. As a suggestion - could you write a &amp;#39;gotcha&amp;#39; post for the community on the usage of the -Encoding parameter and plausible scenarios where this parameter makes a difference? Cheers. Craig.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3455356" width="1" height="1"&gt;</description></item><item><title>re: Use PowerShell to Work with CSV Formatted Text</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2011/09/23/use-powershell-to-work-with-csv-formatted-text.aspx#3455155</link><pubDate>Fri, 23 Sep 2011 10:30:12 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3455155</guid><dc:creator>Q</dc:creator><description>&lt;p&gt;Thanks for the article.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3455155" width="1" height="1"&gt;</description></item><item><title>re: Use PowerShell to Work with CSV Formatted Text</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2011/09/23/use-powershell-to-work-with-csv-formatted-text.aspx#3455154</link><pubDate>Fri, 23 Sep 2011 10:28:25 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3455154</guid><dc:creator>camlost</dc:creator><description>&lt;p&gt;Another useful parameter is -Encoding.&lt;/p&gt;
&lt;p&gt;Example:&lt;/p&gt;
&lt;p&gt;Get-Mailbox mbox_* | Select-Object DisplayName, Name, Database, ProhibitSendReceiveQuota | Export-CSV \mbox.csv -NoTypeInformation -Delimiter &amp;quot;;&amp;quot; -Encoding utf8; start \mbox.csv&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3455154" width="1" height="1"&gt;</description></item></channel></rss>