<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Ramblings of a Coder&#039;s Mind &#187; PowerShell</title>
	<atom:link href="http://karunab.com/tag/powershell/feed/" rel="self" type="application/rss+xml" />
	<link>http://karunab.com</link>
	<description>Got Tech? Will Hack.</description>
	<lastBuildDate>Thu, 06 Oct 2011 10:48:07 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>File list generator v1.1</title>
		<link>http://karunab.com/2010/02/14/file-list-generator-v1-1/</link>
		<comments>http://karunab.com/2010/02/14/file-list-generator-v1-1/#comments</comments>
		<pubDate>Sun, 14 Feb 2010 07:46:06 +0000</pubDate>
		<dc:creator>Karun</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[File List Generator]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Source]]></category>

		<guid isPermaLink="false">http://karunab.com/?p=284</guid>
		<description><![CDATA[On a lazy Sunday afternoon when you&#8217;ve got nothing better to do, you either write rather useless scripts or update them. I chose to do the latter. The file list generation script I wrote some time back was mainly to generate a list of movies I have. When I generated a list of all the <a href='http://karunab.com/2010/02/14/file-list-generator-v1-1/' class='excerpt-more'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p>On a lazy Sunday afternoon when you&#8217;ve got nothing better to do, you either write <a title="Clean File List Generation with PowerShell Script" href="http://karunab.com/2009/12/06/clean-file-list-generation-with-powershell-script/" target="_blank">rather useless scripts</a> or update them. I chose to do the latter.</p>
<p>The <a title="Clean File List Generation with PowerShell Script" href="Clean File List Generation with PowerShell Script" target="_blank">file list generation script</a> I wrote some time back was mainly to generate a list of movies I have. When I generated a list of all the HD movies I have on disk, I realized, my list was being ruined by loads of sample files which escape the file filter because they are the same extension as the videos themselves. So I decided to write a simple fix to remove all files with &#8220;sample&#8221; in it. Of course, this is activated by a command line switch which is by default off. The extension list now ignores all images (pngs, jpgs and bmps) so my file list no longer has any screen shots.</p>
<p>Here&#8217;s a couple of sample script calls</p>
<blockquote><p>C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe <em>-command</em> &#8220;<strong>&amp; &#8216;C:\Users\Karun\My Scripts\filelist.ps1</strong>&#8216;&#8221; &#8220;<strong>H:\Movies\HQ</strong>&#8221;<br />
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe <em>-command</em> &#8220;<strong>&amp; &#8216;C:\Users\Karun\My Scripts\filelist.ps1</strong>&#8216;&#8221; &#8220;<strong>H:\Movies</strong><strong></strong>&#8221; &#8220;<strong>true</strong>&#8221;<br />
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe <em>-command</em> &#8220;<strong>&amp; &#8216;C:\Users\Karun\My Scripts\filelist.ps1</strong>&#8216;&#8221; &#8220;<strong>H:\Movies</strong><strong></strong>&#8221; &#8220;<strong>true</strong>&#8221; &#8220;<strong>true</strong>&#8220;</p></blockquote>
<p>The first one will call on the script and generate an output. The second will do so recursively. The third one will ignore all files with the word &#8220;sample&#8221; in them. Simple enough? Go <a title="View Source  Code" href="http://svn.jalife.net/Random__Code/markup/HEAD/PowerShell___filelist.ps1" target="_blank">get the code</a> and have fun with it!</p>
<p><a title="View Source Code" href="http://svn.jalife.net/Random__Code/markup/HEAD/PowerShell___filelist.ps1" target="_blank">View Script Source Code</a> | <a title="Download Script  Source Code" href="http://svn.jalife.net/Random__Code/downloadfile/HEAD/PowerShell___filelist.ps1" target="_blank">Download Script Source Code</a></p>
<p>If you&#8217;re having trouble executing the script, you should consider signing your PowerShell scripts. <a title="Scott Hanselman on  &quot;Signing PowerShell Scripts&quot;" href="http://www.hanselman.com/blog/SigningPowerShellScripts.aspx" target="_blank">Scott Hanselman has written a great post on how to do so</a>. Go read it! You could simply <em>Set-ExecutionPolicy</em> to <em>Unrestricted</em> but then you&#8217;d be leaving your system open to attacks. Don&#8217;t blame anyone but yourself if you run someone else&#8217;s unsafe code and screw something up :) You have been warned :)</p>
]]></content:encoded>
			<wfw:commentRss>http://karunab.com/2010/02/14/file-list-generator-v1-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Clean File List Generation with PowerShell Script</title>
		<link>http://karunab.com/2009/12/06/clean-file-list-generation-with-powershell-script/</link>
		<comments>http://karunab.com/2009/12/06/clean-file-list-generation-with-powershell-script/#comments</comments>
		<pubDate>Sun, 06 Dec 2009 01:46:06 +0000</pubDate>
		<dc:creator>Karun</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[File List Generator]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Source]]></category>

		<guid isPermaLink="false">http://karunab.com/?p=275</guid>
		<description><![CDATA[I have a whole load of movies that I&#8217;d like to generate a list of. I considered writing a batch script but it didn&#8217;t really do something I needed. I ended up writing my first regular use (non test) PowerScript and here&#8217;s how. My first requirement was to list all my 1080p movies and for <a href='http://karunab.com/2009/12/06/clean-file-list-generation-with-powershell-script/' class='excerpt-more'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p>I have a whole load of movies that I&#8217;d like to generate a list of. I considered writing a batch script but it didn&#8217;t really do something I needed. I ended up writing my first regular use (non test) PowerScript and here&#8217;s how.</p>
<p>My first requirement was to list all my 1080p movies and for the list to leave out all the subtitles. So I was looking for a function to list files (<em>dir</em> in command prompt did that :)) and then remove files by extension. As it turned out, I could list files of a certain extension but not leave out files by extensions. Finally, I had to write the result to file (simple enough to do in command prompt. Use the <em>&gt;</em> operator to direct output of the previous command to a file) So, a quick fix would be to use something like</p>
<blockquote><p>dir *.avi *.mp4 *.mpg *.mpeg *.mkv /B /O N</p></blockquote>
<p>For sub-folders, you can use tree and fiddle around the options but lets face it, as programmers, we want better solutions.</p>
<p>Since the launch of Windows 7, Microsoft has shipped PowerShell with the OS making it much more &#8220;main stream&#8221;. I had played around with PowerShell a couple of years ago when version 1 came out but I thought it was time that I actually made a regular use script.</p>
<p>The core of the script is using <em>get-childitem</em> to get all files and folders in a directory. From there, you can make it go recursive (and look inside sub directories) with a <em>-recurse</em> switch. Little bit of piping allows you to eliminate results you don&#8217;t need. For this, I wrote a simple function.</p>
<blockquote><p>function fileCheck([string]$extention, [string]$attributes) {<br />
# list of rejected extentions<br />
$exts = &#8220;.srt&#8221;,&#8221;.sub&#8221;,&#8221;.idx&#8221;,&#8221;.txt&#8221;,&#8221;.lnk&#8221;</p>
<p>return $exts -notcontains $extention -and $attributes -ne &#8220;Directory&#8221;<br />
}</p></blockquote>
<p>As you&#8217;ve probably figured out, this function ignores those file extensions and directories as well from our final file list.</p>
<p>Once you have the list, you can either use $object.Name for full name (ie file name with extension) or $object.BareName for only the file name. On reading the source of my script, you&#8217;ll see I&#8217;m using both and also writing a count of the number of files in a file named <em>list.txt</em>. The first part of the file is a human readable list for your consumption using new lines for separation. The second is a single line output of all files using commas for separation and containing a file count at the end. The latter is simply for copy pasting into chats (like IRC) where you can&#8217;t spam with a huge multi-line list.</p>
<p>I went on then to add more code to handle command line inputs so that you can make shortcuts from folders and call the script. I have attached a couple of sample script calls</p>
<blockquote><p>C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe <em>-command</em> &#8220;<strong>&amp; &#8216;C:\Users\Karun\My Scripts\filelist.ps1</strong>&#8216;&#8221; &#8220;<strong>H:\Movies\HQ</strong>&#8221;<br />
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe <em>-command</em> &#8220;<strong>&amp; &#8216;C:\Users\Karun\My Scripts\filelist.ps1</strong>&#8216;&#8221; &#8220;<strong>H:\Movies</strong>&#8221; &#8220;<strong>true</strong>&#8220;</p></blockquote>
<p>The first one will call on the script and generate an output. The second will do so recursively. Simple enough? Go <a title="View Source Code" href="http://svn.jalife.net/Random__Code/markup/HEAD/PowerShell___filelist.ps1" target="_blank">get the code</a> and have fun with it!</p>
<p><a title="View Source Code" href="http://svn.jalife.net/Random__Code/markup/HEAD/PowerShell___filelist.ps1" target="_blank">View Script Source Code</a> | <a title="Download Script Source Code" href="http://svn.jalife.net/Random__Code/downloadfile/HEAD/PowerShell___filelist.ps1" target="_blank">Download Script Source Code</a></p>
<p>If you&#8217;re having trouble executing the script, you should consider signing your PowerShell scripts. <a title="Scott Hanselman on &quot;Signing PowerShell Scripts&quot;" href="http://www.hanselman.com/blog/SigningPowerShellScripts.aspx" target="_blank">Scott Hanselman has written a great post on how to do so</a>. Go read it! You could simply <em>Set-ExecutionPolicy</em> to <em>Unrestricted</em> but then you&#8217;d be leaving your system open to attacks. Don&#8217;t blame anyone but yourself if you run someone else&#8217;s unsafe code and screw something up :) You have been warned :)</p>
]]></content:encoded>
			<wfw:commentRss>http://karunab.com/2009/12/06/clean-file-list-generation-with-powershell-script/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

