<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://powershell.com/cs/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>Search results for 'app:weblogs' matching tags 'Weekend Scripter' and 'CSV and other delimited files'</title><link>http://powershell.com/cs/search/SearchResults.aspx?q=app:weblogs&amp;tag=Weekend+Scripter,CSV+and+other+delimited+files&amp;orTags=0&amp;o=DateDescending</link><description>Search results for 'app:weblogs' matching tags 'Weekend Scripter' and 'CSV and other delimited files'</description><dc:language>en-US</dc:language><generator>CommunityServer 2008.5 (Build: 30929.2835)</generator><item><title>Learn How to Manually Create a CSV File in PowerShell</title><link>http://powershell.com/cs/blogs/hey-scriptingguy/archive/2012/03/24/learn-how-to-manually-create-a-csv-file-in-powershell.aspx</link><pubDate>Sat, 24 Mar 2012 05:00:00 GMT</pubDate><guid isPermaLink="false">f421715f-7aba-45f0-8a8d-44de5318a3a7:15518</guid><dc:creator>Anonymous</dc:creator><description>&lt;p&gt;&lt;b&gt;Summary&lt;/b&gt;: The Scripting Wife learns how to manually create a CSV file in this beginner Windows PowerShell blog.&lt;/p&gt;
&lt;p&gt;Microsoft Scripting Guy, Ed Wilson, is here. Ah, it is the weekend. It seems that this week has been rather long, although I know that is a misconception because each week only has 168 hours in it. I guess it is kind of like one of the characters in &lt;a href="http://en.wikipedia.org/wiki/One_Flew_Over_the_Cuckoo%27s_Nest_(novel)" target="_blank"&gt;One Flew Over the Cuckoo&amp;#39;s Nest&lt;/a&gt;, a book I read in high school. They assumed that the staff sped up the clock when they were having fun, and slowed down the clock when they were doing things they disliked as a way of punishing them. Anyway, this morning I am in my office busily working on my new Microsoft Press book, &lt;a href="http://shop.oreilly.com/product/0790145337382.do" target="_blank"&gt;Windows PowerShell 3.0 Step by Step&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&amp;ldquo;Hmmm&amp;hellip;I like the new &lt;b&gt;Where&lt;/b&gt; clause syntax in Windows PowerShell&amp;nbsp;3.0,&amp;rdquo; I said to myself.&lt;/p&gt;
&lt;p&gt;&amp;ldquo;So what is a CSV?&amp;rdquo; said the Scripting Wife as she jolted me from my mental revelry.&lt;/p&gt;
&lt;p&gt;&amp;ldquo;Is it a model of a car?&amp;rdquo; I facetiously queried.&lt;/p&gt;
&lt;p&gt;&amp;ldquo;No. Not even close, Script Monkey,&amp;rdquo; she shot back, &amp;ldquo;Try again.&amp;rdquo;&lt;/p&gt;
&lt;p&gt;&amp;ldquo;OK. It is a comma-separated value type of text file,&amp;rdquo; I said.&lt;/p&gt;
&lt;p&gt;&amp;ldquo;Correct. Give the Script Monkey a peanut,&amp;rdquo; she said.&lt;/p&gt;
&lt;p&gt;&amp;ldquo;So why do you want to know about CSV files?&amp;rdquo; I asked.&lt;/p&gt;
&lt;p&gt;&amp;ldquo;Because silly, it is in the &lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2012/02/05/2012-scripting-games-study-guide-a-resource-for-learning-powershell.aspx" target="_blank"&gt;2012 Scripting Games Study Guide&lt;/a&gt;, and the games start in exactly nie days,&amp;rdquo; she replied.&lt;/p&gt;
&lt;p&gt;&amp;ldquo;OK. What do you want to know about CSV files?&amp;rdquo; I asked.&lt;/p&gt;
&lt;p&gt;&amp;ldquo;Everything.&amp;rdquo;&lt;/p&gt;
&lt;p&gt;&amp;ldquo;I see. Well, you could start by &lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/tags/windows+powershell/csv+and+other+delimited+files/" target="_blank"&gt;reading all the CSV blogs&lt;/a&gt; I have written on the Hey, Scripting Guy! Blog.&amp;rdquo;&lt;/p&gt;
&lt;p&gt;&amp;ldquo;I could, but I want you to teach me. After all, you are the world famous Scripting Guy.&amp;rdquo;&lt;/p&gt;
&lt;h1&gt;Manually creating a CSV File&lt;/h1&gt;
&lt;p&gt;&amp;ldquo;What I am going to show you today is how to create CSV file manually. The first thing you need to do is to create a here string,&amp;rdquo; I said while turning my laptop screen so she could see.&lt;/p&gt;
&lt;p&gt;&amp;ldquo;A hear string? What is this? Like a symphony or something?&amp;rdquo; she quipped.&lt;/p&gt;
&lt;p&gt;&amp;ldquo;Try to stay with me. A here string allows you to create a string without worrying about any sort of formatting like quotation marks and commas, which are two things that CSV files really love, and that Windows PowerShell in general balks at.&amp;rdquo;&lt;/p&gt;
&lt;p&gt;&amp;ldquo;OK. So how do I create this magical here string?&amp;rdquo; she asked with obvious signs of skepticism.&lt;/p&gt;
&lt;h1&gt;Use @&amp;rdquo; to begin and &amp;ldquo;@ to end a here string&lt;/h1&gt;
&lt;p&gt;&amp;ldquo;The first thing I do is use a variable to hold the resulting string. Then I begin the here string with the at plus quotation symbols (@&amp;rdquo;). Then I immediately press ENTER, and I add my column headings. A comma separates each heading, and then I again press ENTER. Now I add the value for each column and I use a comma to separate the values.&amp;rdquo;&lt;/p&gt;
&lt;p&gt;&amp;ldquo;That is why it is called a comma-separated value file?&amp;rdquo; she asked.&lt;/p&gt;
&lt;p&gt;&amp;ldquo;Exactly. When all of the rows of data are typed, press ENTER again, and I close the here string with the quotation mark plus at symbols (&amp;ldquo;@) and again press ENTER.&amp;rdquo;&lt;/p&gt;
&lt;p&gt;&amp;ldquo;OK,&amp;rdquo; she said somewhat skeptically.&lt;/p&gt;
&lt;p&gt;&amp;ldquo;Why don&amp;rsquo;t you give it a try,&amp;rdquo; I said as I turned the laptop over to her.&lt;/p&gt;
&lt;p&gt;The Scripting Wife opened the Windows PowerShell console, and typed the following on the first line. In the following code, &amp;lt;enter&amp;gt; represents the ENTER or Return key (ASCII 13) (8 ).&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;$csv = @&amp;quot;&amp;lt;enter&amp;gt;&lt;/p&gt;
&lt;p&gt;Next she added the column headings by typing the following.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;quot;index&amp;quot;,&amp;quot;name&amp;quot;&amp;lt;enter&amp;gt;&lt;/p&gt;
&lt;p&gt;After the columns were added, the Scripting Wife added the data. This is shown here.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;1,&amp;quot;ed&amp;quot;&amp;lt;enter&amp;gt;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;2,&amp;quot;teresa&amp;quot;&amp;lt;enter&amp;gt;&lt;/p&gt;
&lt;p&gt;Finally, she closed the here string.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;quot;@&amp;lt;enter&amp;gt;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;lt;enter&amp;gt;&lt;/p&gt;
&lt;p&gt;&amp;ldquo;Now you need to write your CSV data to a file,&amp;rdquo; I said. &amp;ldquo;When you are done, use the &lt;b&gt;Import-CSV &lt;/b&gt;cmdlet to read it back.&amp;rdquo;&lt;/p&gt;
&lt;p&gt;&amp;ldquo;Oh, I can use redirection to create the file,&amp;rdquo; she said.&lt;/p&gt;
&lt;p&gt;The Scripting Wife quickly typed the following.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;$csv &amp;gt;&amp;gt;c:\fso\mycsv.csv&amp;lt;enter&amp;gt;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Import-Csv C:\fso\mycsv.csv&amp;lt;enter&amp;gt;&lt;/p&gt;
&lt;p&gt;&amp;ldquo;Very good. Now store the CSV information back into a new variable, and access the first element in the file,&amp;rdquo; I said.&lt;/p&gt;
&lt;p&gt;&amp;ldquo;Huh? Do you mean for me to use square brackets and see the first row of information?&amp;rdquo;&lt;/p&gt;
&lt;p&gt;&amp;ldquo;Yeah.&amp;rdquo;&lt;/p&gt;
&lt;p&gt;&amp;ldquo;Then why don&amp;rsquo;t you just say that?&amp;rdquo; she chided.&lt;/p&gt;
&lt;p&gt;The Scripting Wife typed the following.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;$mycsv = Import-Csv C:\fso\mycsv.csv&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;$mycsv[0]&lt;/p&gt;
&lt;p&gt;&amp;ldquo;Do you see that your first row of data contains two items&amp;mdash;the index and the name?&amp;rdquo; I asked.&lt;/p&gt;
&lt;p&gt;&amp;ldquo;Yes.&amp;rdquo;&lt;/p&gt;
&lt;p&gt;&amp;ldquo;You can use dotted notation to access the specific column of information. These act just like properties. Why don&amp;rsquo;t you get the name from the second record?&amp;rdquo; I suggested.&lt;/p&gt;
&lt;p&gt;The Scripting Wife typed the following.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;$mycsv[1].name&lt;/p&gt;
&lt;p&gt;&amp;ldquo;So how does all this look?&amp;rdquo; the Scripting Wife asked as she turned the monitor over so I could see.&lt;/p&gt;
&lt;p&gt;As I looked at the screen, I beamed. &amp;ldquo;It is perfect.&amp;rdquo; The screen is shown in the image that follows.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/2055.HSG_2D00_3_2D00_24_2D00_12_2D00_01.png"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/2055.HSG_2D00_3_2D00_24_2D00_12_2D00_01.png" alt="Image of command output" title="Image of command output" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;ldquo;Cool,&amp;rdquo; she said as she jumped up and prepared to leave.&lt;/p&gt;
&lt;p&gt;&amp;ldquo;By the way, how did you do on the new 2012 Scripting Games PowerShell Quiz?&amp;rdquo; I asked.&lt;/p&gt;
&lt;p&gt;But by this time she was long gone. Perhaps she did not hear. Or maybe she did&amp;hellip;&lt;/p&gt;
&lt;p&gt;I invite you to follow me on &lt;a href="http://bit.ly/scriptingguystwitter" target="_blank"&gt;Twitter&lt;/a&gt; and &lt;a href="http://bit.ly/scriptingguysfacebook" target="_blank"&gt;Facebook&lt;/a&gt;. If you have any questions, send email to me at &lt;a href="mailto:scripter@microsoft.com" target="_blank"&gt;scripter@microsoft.com&lt;/a&gt;, or post your questions on the &lt;a href="http://bit.ly/scriptingforum" target="_blank"&gt;Official Scripting Guys Forum&lt;/a&gt;. See you tomorrow. Until then, peace.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Ed Wilson, Microsoft Scripting Guy&lt;/b&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3488314" width="1" height="1" alt="" /&gt;</description></item><item><title>Use PowerShell to Automatically Create a CSV File</title><link>http://powershell.com/cs/blogs/hey-scriptingguy/archive/2011/11/06/use-powershell-to-automatically-create-a-csv-file.aspx</link><pubDate>Sun, 06 Nov 2011 05:00:00 GMT</pubDate><guid isPermaLink="false">f421715f-7aba-45f0-8a8d-44de5318a3a7:13090</guid><dc:creator>Anonymous</dc:creator><description>&lt;p&gt;&lt;span style="font-size:small;"&gt;&lt;span style="font-family:Segoe;"&gt;&lt;strong&gt;Summary:&lt;/strong&gt; Learn how to use Windows PowerShell to automatically create a CSV file.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:Segoe;font-size:small;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:Segoe;font-size:small;"&gt;Microsoft Scripting Guy Ed Wilson here. I am about finished playing around with CSV files for the time being. I do not always use the &lt;b&gt;ConvertTo-CSV&lt;/b&gt; or the &lt;b&gt;Export-CSV&lt;/b&gt; cmdlet. There are times that I write code and create my own CSV file from scratch. An example of this is the CreateCSVFile.ps1 script that follows:&lt;/span&gt;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&lt;span style="font-size:small;"&gt;&lt;b&gt;&lt;span style="font-family:Segoe;"&gt;CreateCSVFile.ps1&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&lt;span style="font-family:Segoe;font-size:small;"&gt;1..5 | ForEach-Object -begin { &amp;quot;path,itemtype&amp;quot; } -process{ &lt;/span&gt;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&lt;span style="font-family:Segoe;font-size:small;"&gt;&amp;nbsp;&amp;quot;c:\folder$_,directory&amp;quot; &lt;/span&gt;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&lt;span style="font-family:Segoe;font-size:small;"&gt;&amp;nbsp;for($i=0; $i -le 10; $i++) {&amp;quot;c:\folder$_\file$i.txt,file&amp;quot;}} | &lt;/span&gt;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&lt;span style="font-family:Segoe;font-size:small;"&gt;&amp;nbsp;Out-File c:\fso\filesAndFolders.csv -Encoding ascii -Force&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:Segoe;font-size:small;"&gt;This script creates a CSV file that I can use to create a nested folder hierarchy. It is useful when testing certain applications, or for testing a Windows PowerShell script. I create five folders, and inside each folder I create 11 files. The folders are off the root and are named Folder1, Folder2, Folder3, Folder4, and Folder5. The files are named file0, file1, and so on through file10.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:Segoe;font-size:small;"&gt;When using the &lt;b&gt;Foreach-Object&lt;/b&gt;, I use the &lt;i&gt;begin &lt;/i&gt;parameter to perform an action once. Inside the process block, I create the path to the folder, and I include the &lt;b&gt;itemtype&lt;/b&gt; of directory. Next, I use a loop to create the path to the files. &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:Segoe;font-size:small;"&gt;The newly created CSV file is shown in the following figure.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:Segoe;font-size:small;"&gt;&lt;a href="http://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/6404.hsg_2D00_11_2D00_6_2D00_11_2D00_01.png"&gt;&lt;img style="border:0px;" title="Image of newly created CSV file" alt="Image of newly created CSV file" src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/6404.hsg_2D00_11_2D00_6_2D00_11_2D00_01.png" width="429" height="550" /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:Segoe;font-size:small;"&gt;I use the &lt;b&gt;Import-CSV&lt;/b&gt; cmdlet to import the CSV file, and I pipe it to the &lt;b&gt;New-Item&lt;/b&gt; cmdlet as shown here:&lt;/span&gt;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&lt;span style="font-family:Segoe;font-size:small;"&gt;Import-Csv C:\fso\FilesAndFolders.csv | New-Item&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:Segoe;font-size:small;"&gt;The command and associated output are shown in the following figure.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:Segoe;font-size:small;"&gt;&lt;a href="http://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/0624.hsg_2D00_11_2D00_6_2D00_11_2D00_02.png"&gt;&lt;img style="border:0px;" title="Image of command and associated output" alt="Image of command and associated output" src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/0624.hsg_2D00_11_2D00_6_2D00_11_2D00_02.png" /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:Segoe;font-size:small;"&gt;One of the folders and associated files is shown in the following figure.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:Segoe;font-size:small;"&gt;&lt;a href="http://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/0020.hsg_2D00_11_2D00_6_2D00_11_2D00_03.png"&gt;&lt;img style="border:0px;" title="Image of folder and files" alt="Image of folder and files" src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/0020.hsg_2D00_11_2D00_6_2D00_11_2D00_03.png" /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:Segoe;font-size:small;"&gt;As you can see, there are times when it is easier to use a little bit of code to create the CSV file. This makes it a lot easier when it comes time to import the file and to pipeline it to another cmdlet.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:Segoe;font-size:small;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:Segoe;font-size:small;"&gt;This is all for today. I hope you have a great day. See you next week.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:Segoe;font-size:small;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:small;"&gt;&lt;span style="font-family:Segoe;"&gt;I invite you to follow me on &lt;/span&gt;&lt;a href="http://bit.ly/scriptingguystwitter" target="_blank"&gt;&lt;span style="font-family:Segoe;"&gt;Twitter&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family:Segoe;"&gt; and &lt;/span&gt;&lt;a href="http://bit.ly/scriptingguysfacebook"&gt;&lt;span style="font-family:Segoe;"&gt;Facebook&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family:Segoe;"&gt;. If you have any questions, send email to me at &lt;/span&gt;&lt;a href="mailto:scripter@microsoft.com" target="_blank"&gt;&lt;span style="font-family:Segoe;"&gt;scripter@microsoft.com&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family:Segoe;"&gt;, or post your questions on the &lt;/span&gt;&lt;a href="http://bit.ly/scriptingforum" target="_blank"&gt;&lt;span style="font-family:Segoe;"&gt;Official Scripting Guys Forum&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family:Segoe;"&gt;. See you tomorrow. Until then, peace.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:small;"&gt;&lt;b&gt;Ed Wilson, Microsoft Scripting Guy&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:Segoe;font-size:small;"&gt;&lt;/span&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:Segoe;font-size:small;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3462932" width="1" height="1" alt="" /&gt;</description></item><item><title>Use PowerShell to Read CSV Files and Create Files and Folders</title><link>http://powershell.com/cs/blogs/hey-scriptingguy/archive/2011/11/05/use-powershell-to-read-csv-files-and-create-files-and-folders.aspx</link><pubDate>Sat, 05 Nov 2011 05:00:00 GMT</pubDate><guid isPermaLink="false">f421715f-7aba-45f0-8a8d-44de5318a3a7:13083</guid><dc:creator>Anonymous</dc:creator><description>&lt;p&gt;&lt;span style="font-size:small;"&gt;&lt;span style="font-family:Segoe;"&gt;&lt;strong&gt;Summary:&lt;/strong&gt; Learn how to use Windows PowerShell to read CSV files and create files and folders.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:Segoe;font-size:small;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:Segoe;font-size:small;"&gt;Microsoft Scripting Guy Ed Wilson here. This past week has been fun. I enjoy talking about comma-separated value files (CSV) because they are very flexible, and Windows PowerShell makes working with them really easy. &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:small;"&gt;&lt;span style="font-family:Segoe;"&gt;One of the cool things that can be done using a CSV file was only alluded to in yesterday&amp;rsquo;s post, &lt;/span&gt;&lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2011/11/04/use-a-csv-file-to-populate-parameters-of-powershell-cmdlets.aspx"&gt;&lt;span style="font-family:Segoe;"&gt;Use a CSV File to Populate Parameters of PowerShell Cmdlets&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family:Segoe;"&gt;. &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:Segoe;font-size:small;"&gt;In yesterday&amp;rsquo;s article, I piped information from a CSV file to the &lt;b&gt;Get-WmiObject&lt;/b&gt; cmdlet. The problem is that the &lt;b&gt;Get-WmiObject&lt;/b&gt; cmdlet does not accept piped input for either the &lt;i&gt;class &lt;/i&gt;or &lt;i&gt;computername &lt;/i&gt;parameter. &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:Segoe;font-size:small;"&gt;However, the &lt;b&gt;New-Item&lt;/b&gt; cmdlet does accept piped input. When a cmdlet accepts piped input, it will automatically match column names from a CSV file with parameter names of the cmdlet receiving the piped input. This allows for some extremely powerful scenarios. Here are the steps for this scenario:&lt;/span&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;span style="font-size:small;"&gt;&lt;span style="font-family:Segoe;"&gt;Create a CSV file that uses column headings that are the same as the parameter names for the cmdlet to use.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="font-size:small;"&gt;&lt;span style="font-family:Segoe;"&gt;Use the &lt;b&gt;Import-CSV&lt;/b&gt; cmdlet to read the CSV file and to create a custom object from that file.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="font-size:small;"&gt;&lt;span style="font-family:Segoe;"&gt;Pipe the results to a cmdlet that accepts piped input.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;span style="font-family:Segoe;font-size:small;"&gt;Suppose I create a CSV file that contains a file system layout. In that file, I specify the name of the folder and the names of files I want to create in that folder. I use the column names of &lt;b&gt;path&lt;/b&gt; and &lt;b&gt;itemtype&lt;/b&gt; because those are the parameter names used by the &lt;b&gt;New-Item&lt;/b&gt; cmdlet. A sample CSV file that meets these requirements is shown in the following figure&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:Segoe;font-size:small;"&gt;&lt;a href="http://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/4101.hsg_2D00_11_2D00_5_2D00_11_2D00_01.png"&gt;&lt;img style="border:0px;" title="Image of CSV file that meets requirements" alt="Image of CSV file that meets requirements" src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/4101.hsg_2D00_11_2D00_5_2D00_11_2D00_01.png" width="427" height="435" /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:Segoe;font-size:small;"&gt;After I have created my file, the Windows PowerShell command itself is trivial. I use the &lt;b&gt;Import-CSV&lt;/b&gt; cmdlet to read the CSV file, and I pipe the results to the &lt;b&gt;New-Item&lt;/b&gt; cmdlet. This command is shown here:&lt;/span&gt;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&lt;span style="font-family:Segoe;font-size:small;"&gt;Import-Csv C:\fso\FilesAndFolders.csv | New-Item&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:Segoe;font-size:small;"&gt;The use of the command to read a CSV file and create files and folders along with the associated output are shown in the following figure.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:Segoe;font-size:small;"&gt;&lt;a href="http://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/3286.hsg_2D00_11_2D00_5_2D00_11_2D00_02.png"&gt;&lt;img style="border:0px;" title="Image of command and associated output" alt="Image of command and associated output" src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/3286.hsg_2D00_11_2D00_5_2D00_11_2D00_02.png" width="522" height="280" /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:Segoe;font-size:small;"&gt;When this command runs, the following is displayed in Windows Explorer.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:Segoe;font-size:small;"&gt;&lt;a href="http://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/2577.hsg_2D00_11_2D00_5_2D00_11_2D00_03.png"&gt;&lt;img style="border:0px;" title="Image of what is displayed in Windows Explorer when command runs" alt="Image of what is displayed in Windows Explorer when command runs" src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/2577.hsg_2D00_11_2D00_5_2D00_11_2D00_03.png" width="525" height="419" /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:Segoe;font-size:small;"&gt;That is about all there is to reading a CSV file and automatically creating files and folders. Given the Windows PowerShell providers that work with &lt;b&gt;New-Item&lt;/b&gt;, this one scenario and one cmdlet provide lots of possibilities. And this is only one cmdlet. I will leave it to you to explore and see what you can come up with. Let me know. &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:small;"&gt;&lt;span style="font-family:Segoe;"&gt;I invite you to follow me on &lt;/span&gt;&lt;a href="http://bit.ly/scriptingguystwitter" target="_blank"&gt;&lt;span style="font-family:Segoe;"&gt;Twitter&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family:Segoe;"&gt; and &lt;/span&gt;&lt;a href="http://bit.ly/scriptingguysfacebook"&gt;&lt;span style="font-family:Segoe;"&gt;Facebook&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family:Segoe;"&gt;. If you have any questions, send email to me at &lt;/span&gt;&lt;a href="mailto:scripter@microsoft.com" target="_blank"&gt;&lt;span style="font-family:Segoe;"&gt;scripter@microsoft.com&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family:Segoe;"&gt;, or post your questions on the &lt;/span&gt;&lt;a href="http://bit.ly/scriptingforum" target="_blank"&gt;&lt;span style="font-family:Segoe;"&gt;Official Scripting Guys Forum&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family:Segoe;"&gt;. See you tomorrow. Until then, peace.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:Segoe;font-size:small;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:small;"&gt;&lt;b&gt;Ed Wilson, Microsoft Scripting Guy&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:Segoe;font-size:small;"&gt;&lt;/span&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:Segoe;font-size:small;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3462917" width="1" height="1" alt="" /&gt;</description></item></channel></rss>