<?xml version="1.0" encoding="utf-8"?><?xml-stylesheet type='text/xsl' href='http://dverweij.spaces.live.com/mmm2008-07-24_12.50/rsspretty.aspx?rssquery=en-US;http%3a%2f%2fdverweij.spaces.live.com%2fcategory%2fone-liners%2ffeed.rss' version='1.0'?><rss version="2.0" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:msn="http://schemas.microsoft.com/msn/spaces/2005/rss" xmlns:live="http://schemas.microsoft.com/live/spaces/2006/rss" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:cf="http://www.microsoft.com/schemas/rss/core/2005" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Just Powershell it: one-liners</title><description /><link>http://dverweij.spaces.live.com/?_c11_BlogPart_BlogPart=blogview&amp;_c=BlogPart&amp;partqs=catone-liners</link><language>en-US</language><pubDate>Sat, 12 Jul 2008 01:36:10 GMT</pubDate><lastBuildDate>Sat, 12 Jul 2008 01:36:10 GMT</lastBuildDate><generator>Microsoft Spaces v1.1</generator><docs>http://www.rssboard.org/rss-specification</docs><ttl>60</ttl><cf:parentRSS>http://dverweij.spaces.live.com/blog/feed.rss</cf:parentRSS><live:type>blogcategory</live:type><live:identity><live:id>-6645245869990399496</live:id><live:alias>dverweij</live:alias></live:identity><cf:listinfo><cf:group ns="http://schemas.microsoft.com/live/spaces/2006/rss" element="typelabel" label="Type" /><cf:group ns="http://schemas.microsoft.com/live/spaces/2006/rss" element="tag" label="Tag" /><cf:group element="category" label="Category" /><cf:sort element="pubDate" label="Date" data-type="date" default="true" /><cf:sort element="title" label="Title" data-type="string" /><cf:sort ns="http://purl.org/rss/1.0/modules/slash/" element="comments" label="Comments" data-type="number" /></cf:listinfo><item><title>A complete directory listing</title><link>http://dverweij.spaces.live.com/Blog/cns!A3C75816DA1731F8!137.entry</link><description>&lt;div&gt; &lt;/div&gt;
&lt;div&gt;Sometimes there are things I just want to try the hard way. Of course you can get a complete directory listing by using &lt;/div&gt;
&lt;div&gt;get-childitem -recurse, but you can also do it differently. Same output, but much more fun to try and héy, you want to learn powershell or you don't. I do. &lt;/div&gt;
&lt;div&gt;So the stuff below might seem useless effort, but you can use it for much more than just a directorylisting.&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;It's easy to get a directory listing one level down, or two, or three, or whatever. Just as long as you know how many subs there are. So what if you don't know how many levels down a directorystructure goes or if you just don't care. Then you can do the following:&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;&lt;font style="background-color:#333399" face=Arial color="#ffffff" size=2&gt;PS&amp;gt;&amp;gt;Function dirlist {ls $_.FullName|Foreach {$_;if ($_.Mode -like &amp;quot;d*&amp;quot;){dirlist}}};Get-Item * |Foreach {$_;if&lt;br&gt; ($_.Mode -like &amp;quot;d*&amp;quot;){dirlist}}&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font face=Arial size=2&gt;&lt;/font&gt; &lt;/div&gt;
&lt;div&gt;&lt;font face=Arial size=2&gt;If you do the above you'll get the info, but in an pretty unreadable format, so just format the output:&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font face=Arial size=2&gt;&lt;/font&gt; &lt;/div&gt;
&lt;div&gt;&lt;font face=Arial size=2&gt;
&lt;div&gt;&lt;font size=2&gt;&lt;font style="background-color:#333399" face=Arial color="#ffffff"&gt;PS&amp;gt;&amp;gt;Function dirlist {ls $_.FullName|Foreach {$_;if ($_.Mode -like &amp;quot;d*&amp;quot;){dirlist}}};Get-Item * |Foreach {$_;if&lt;br&gt; ($_.Mode -like &amp;quot;d*&amp;quot;){dirlist}} |ft name,fullname&lt;/font&gt;&lt;/font&gt;&lt;/div&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font face=Arial size=2&gt;&lt;/font&gt; &lt;/div&gt;
&lt;div&gt;&lt;font face=Arial size=2&gt;And you can sort on what and how you want&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font face=Arial size=2&gt;&lt;/font&gt; &lt;/div&gt;
&lt;div&gt;&lt;font face=Arial size=2&gt;
&lt;div&gt;&lt;font size=2&gt;&lt;font style="background-color:#333399" face=Arial color="#ffffff"&gt;PS&amp;gt;&amp;gt;Function dirlist {ls $_.FullName|Foreach {$_;if ($_.Mode -like &amp;quot;d*&amp;quot;){dirlist}}};Get-Item * |Foreach {$_;if&lt;br&gt; ($_.Mode -like &amp;quot;d*&amp;quot;){dirlist}} |Sort-Object -descending creationtime|ft name,creationtime&lt;/font&gt;&lt;/font&gt;&lt;/div&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font face=Arial size=2&gt;&lt;/font&gt; &lt;/div&gt;
&lt;div&gt;&lt;font face=Arial size=2&gt;Or just export to a csv so that later, you can do whatever you want. Sort it, filter, choose output format, etc, etc.&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font face=Arial size=2&gt;&lt;/font&gt; &lt;/div&gt;
&lt;div&gt;
&lt;div&gt;&lt;font size=2&gt;&lt;font style="background-color:#333399" face=Arial color="#ffffff"&gt;PS&amp;gt;&amp;gt;Function dirlist {ls $_.FullName|Foreach {$_;if ($_.Mode -like &amp;quot;d*&amp;quot;){dirlist}}};Get-Item * |Foreach {$_;if&lt;br&gt; ($_.Mode -like &amp;quot;d*&amp;quot;){dirlist} | Export-csv dirlist.csv&lt;/font&gt;&lt;/font&gt;&lt;/div&gt;&lt;/div&gt;
&lt;div&gt;&lt;font face=Arial size=2&gt;&lt;/font&gt; &lt;/div&gt;
&lt;div&gt;**update**&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;As Vinicius Canto mentioned in the reactions, there is a better way to determine if a childitem is a container (directory) or not. This is done by checking the NoteProperty &amp;quot;$_.PSIsContainer&amp;quot;, instead of what I used: &amp;quot;if ($_.Mode -like &amp;quot;d*&amp;quot;)&amp;quot; or using the -band operator as Vinicius used on his blog at &lt;a href="http://viniciuscanto.blogspot.com/2007/01/dir-ad-no-powershell-onde-ele-foi-parar.html"&gt;http://viniciuscanto.blogspot.com/2007/01/dir-ad-no-powershell-onde-ele-foi-parar.html&lt;/a&gt;&amp;quot;&lt;/div&gt;
&lt;div&gt;The NoteProperty &amp;quot;PSIsContainer&amp;quot; works faster than doing a compaire. It simply results in a $True of $False&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;This results in:&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;&lt;font size=2&gt;&lt;font style="background-color:#333399" face=Arial color="#ffffff"&gt;PS&amp;gt;&amp;gt;Function dirlist {ls $_.FullName|Foreach {$_;if ($_.PSIsContainer){dirlist}}};Get-Item * |Foreach {$_;if&lt;br&gt; ($_.PSIsContainer){dirlist} | Export-csv dirlist.csv&lt;/font&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;Thanks Vinicius. And Jeffrey Snover who gave the initial hint.&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;&lt;font face=Arial size=2&gt;Grt&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font face=Arial size=2&gt;Dennis&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font size=2&gt;&lt;font style="background-color:#333399" face=Arial color="#ffffff"&gt;&lt;/font&gt;&lt;/font&gt; &lt;/div&gt;&lt;img src="http://c.services.spaces.live.com/CollectionWebService/c.gif?cid=-6645245869990399496&amp;page=RSS%3a+A+complete+directory+listing&amp;referrer=" width="1px" height="1px" border="0" alt=""&gt;&lt;img style="position:absolute" alt="" width="0px" height="0px" src="http://c.live.com/c.gif?NC=31263&amp;amp;NA=1149&amp;amp;PI=73329&amp;amp;RF=&amp;amp;DI=3919&amp;amp;PS=85545&amp;amp;TP=dverweij.spaces.live.com&amp;amp;GT1=dverweij"&gt;</description><comments>http://dverweij.spaces.live.com/Blog/cns!A3C75816DA1731F8!137.entry#comment</comments><guid isPermaLink="true">http://dverweij.spaces.live.com/Blog/cns!A3C75816DA1731F8!137.entry</guid><pubDate>Tue, 09 Jan 2007 09:14:52 GMT</pubDate><slash:comments>4</slash:comments><msn:type>blogentry</msn:type><live:type>blogentry</live:type><live:typelabel>Blog entry</live:typelabel><wfw:commentRss>http://dverweij.spaces.live.com/blog/cns!A3C75816DA1731F8!137/comments/feed.rss</wfw:commentRss><wfw:comment>http://dverweij.spaces.live.com/Blog/cns!A3C75816DA1731F8!137.entry#comment</wfw:comment><dcterms:modified>2007-01-15T07:32:22Z</dcterms:modified></item></channel></rss>