<?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>The Ryan and Jeff Show &#187; Uncategorized</title>
	<atom:link href="http://www.ryanandjeffshow.com/blog/category/uncategorized/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ryanandjeffshow.com/blog</link>
	<description>...Relax, we brought the towel (:P)</description>
	<lastBuildDate>Tue, 18 Aug 2015 05:23:28 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.2.38</generator>
	<item>
		<title>PSG2013: Beginner Event 1: Managing Old Log Files</title>
		<link>http://www.ryanandjeffshow.com/blog/2013/05/02/psg2013-beginner-event-1-managing-log-files/</link>
		<comments>http://www.ryanandjeffshow.com/blog/2013/05/02/psg2013-beginner-event-1-managing-log-files/#comments</comments>
		<pubDate>Thu, 02 May 2013 21:00:13 +0000</pubDate>
		<dc:creator><![CDATA[Jeff Liford]]></dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.ryanandjeffshow.com/blog/?p=239</guid>
		<description><![CDATA[This is my submission for Event 1 in the beginner track for the PowerShell Scripting Games, 2013 Here&#8217;s the instructions. The premise of the event is log files have been allowed to accumulate and are now eating disk space on<span class="ellipsis">&#8230;</span><div class="read-more"><a href="http://www.ryanandjeffshow.com/blog/2013/05/02/psg2013-beginner-event-1-managing-log-files/">Read more &#8250;</a></div><!-- end of .read-more -->]]></description>
				<content:encoded><![CDATA[<p>This is my submission for Event 1 in the beginner track for the <a href="http://scriptinggames.org">PowerShell Scripting Games, 2013</a></p>
<p><a href="http://scriptinggames.org/265642e83094138277ac.pdf">Here&#8217;s the instructions.</a>  The premise of the event is log files have been allowed to accumulate and are now eating disk space on a server.  Files accumulate in C:\Application\Log\[Application Name].  We need to identify and move files that are older than 90 days to an archive located at \\NASServer\Archive.  When moving, the files should retrain the path with the application name in it.  This means C:\Application\Log\App1\OldLogFile.log should land as \\NASServer\Archive\App1\OldLogFile.log.  As concise as possible, One-Liners are appreciated.</p>
<p>Here&#8217;s my submission:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #008000;">#Broken Up</span>
<span style="color: #008080; font-weight: bold;">Get-ChildItem</span> C:\Application\Log\<span style="color: pink;">*</span>\<span style="color: pink;">*</span> <span style="color: pink;">|</span> 
<span style="color: #0000FF;">ForEach</span> <span style="color: #000000;">&#123;</span> 
<span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #008080; font-weight: bold;">Get-Date</span><span style="color: #000000;">&#41;</span><span style="color: pink;">-</span><span style="color: #000080;">$_</span>.lastaccesstime<span style="color: #000000;">&#41;</span>.TotalDays <span style="color: #FF0000;">-gt</span> <span style="color: #804000;">90</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> 
   <span style="color: #008080; font-weight: bold;">Move-Item</span> <span style="color: #000080;">$_</span> \\NASServer\Archive\$<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #000080;">$_</span>.directory<span style="color: #000000;">&#41;</span>.name<span style="color: #000000;">&#41;</span>\$<span style="color: #000000;">&#40;</span><span style="color: #000080;">$_</span>.name<span style="color: #000000;">&#41;</span> 
   <span style="color: #000000;">&#125;</span> 
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #008000;">#Retained on one line</span>
<span style="color: #008080; font-weight: bold;">Get-ChildItem</span> C:\Application\Log\<span style="color: pink;">*</span>\<span style="color: pink;">*</span> <span style="color: pink;">|</span> <span style="color: #0000FF;">ForEach</span> <span style="color: #000000;">&#123;</span> <span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #008080; font-weight: bold;">Get-Date</span><span style="color: #000000;">&#41;</span><span style="color: pink;">-</span><span style="color: #000080;">$_</span>.lastaccesstime<span style="color: #000000;">&#41;</span>.TotalDays <span style="color: #FF0000;">-gt</span> <span style="color: #804000;">90</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> <span style="color: #008080; font-weight: bold;">Move-Item</span> <span style="color: #000080;">$_</span> \\NASServer\Archive\$<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #000080;">$_</span>.directory<span style="color: #000000;">&#41;</span>.name<span style="color: #000000;">&#41;</span>\$<span style="color: #000000;">&#40;</span><span style="color: #000080;">$_</span>.name<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#125;</span> <span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p><span id="more-239"></span></p>
<p><strong>Managing Old Log Files</strong></p>
<p>So first things first, we need to actually go out and get all the log files.  This turned out to be amazingly simple.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #008080; font-weight: bold;">Get-ChildItem</span> C:\Application\Log\<span style="color: pink;">*</span>\<span style="color: pink;">*</span></pre></td></tr></table></div>

<p>I didn&#8217;t realize Get-ChildItem (which is what the dir alias is in PowerShell) would let me double wildcard like this.  I found it just playing around with the cmdlet.  But once I have the return, that is and object for every file from every folder beneath Application\Log, I can start examining them directly to make a decision and do something.</p>
<p>From there I need to identify which files are older than 90 days and take an action.  The LastAccessTime Property of a filesystem object contains a standard date object, which I can simply subtract from the date right now (Get-Date).  This results in a timespan object that has a non-incremental TotalDays property.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #0000FF;">ForEach</span> <span style="color: #000000;">&#123;</span> <span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #008080; font-weight: bold;">Get-Date</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">-</span> <span style="color: #000080;">$_</span>.lastaccesstime<span style="color: #000000;">&#41;</span>.TotalDays <span style="color: #FF0000;">-gt</span> <span style="color: #804000;">90</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> <span style="color: #008000;">#Do Something } }</span></pre></td></tr></table></div>

<p>From here, its just a matter of moving files.  To pick the object to move, I simply specify the object on the pipeline $_.  To retain the folder structure, I had to get a little more creative.  Each filesystem object has a directory property, which is a call for the directory that houses the file.  By calling this and looking at its name, I can specify it in the destination path for Move-Item.  Simply specify the name of the file after we&#8217;ve modified the path.  I need the extra dollar sign to signify to PowerShell that this string should be the result of enumerating that property.  $($_.name) is a variable stand-in for the name of the file i.e. Someoldlogfile.log</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #008080; font-weight: bold;">Move-Item</span> <span style="color: #000080;">$_</span> \\NASServer\Archive\$<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #000080;">$_</span>.directory<span style="color: #000000;">&#41;</span>.name<span style="color: #000000;">&#41;</span>\$<span style="color: #000000;">&#40;</span><span style="color: #000080;">$_</span>.name<span style="color: #000000;">&#41;</span></pre></td></tr></table></div>

<p>Simply string it all together.  No Output if it succeeds, errors are not suppressed.  Move-Item will complain if the destination path does not exist, but on an archive server it stands to reason the path probably already exists, or that I&#8217;d at least be willing to create it the first time I tried to do this task.</p>
<p>The advanced version calls for parameterizing the paths to examine as well as the time-frame to judge on.  That doesn&#8217;t sound terribly difficult, so I will look at it next.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ryanandjeffshow.com/blog/2013/05/02/psg2013-beginner-event-1-managing-log-files/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PowerShell Scripting Games 2013</title>
		<link>http://www.ryanandjeffshow.com/blog/2013/04/21/powershell-scripting-games-2013/</link>
		<comments>http://www.ryanandjeffshow.com/blog/2013/04/21/powershell-scripting-games-2013/#comments</comments>
		<pubDate>Sun, 21 Apr 2013 08:15:50 +0000</pubDate>
		<dc:creator><![CDATA[Jeff Liford]]></dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.ryanandjeffshow.com/blog/?p=204</guid>
		<description><![CDATA[The PowerShell Scripting Games (2013) will be held over the course of about 6 weeks beginning on the 22nd (oh my god that&#8217;s tomorrow!). When I first started learning about PowerShell, previous games were one of my main sources of<span class="ellipsis">&#8230;</span><div class="read-more"><a href="http://www.ryanandjeffshow.com/blog/2013/04/21/powershell-scripting-games-2013/">Read more &#8250;</a></div><!-- end of .read-more -->]]></description>
				<content:encoded><![CDATA[<p>The <a href="http://scriptinggames.org">PowerShell Scripting Games (2013)</a> will be <a href="http://www.powershellmagazine.com/2013/04/14/2013-powershell-scripting-games/">held over the course of about 6 weeks beginning on the 22nd</a> (oh my god that&#8217;s tomorrow!).  When I first started learning about PowerShell, previous games were one of my main sources of instruction.  That said, I&#8217;m planning on trying to participate (work and school schedules allowing).  It helps they break it down to one per week over multiple weeks, so I can use time on the weekends.</p>
<p><span id="more-204"></span></p>
<p>The Scripting Games are broken down into advanced and beginner tracks.  The beginner track appears primarily focused on getting the desired result (functionally) while the advanced tracks seem to be focused on the additional things that make good scripts great (objects, error handling, input handling/validation).  I do not yet think I&#8217;m quite at the &#8220;advanced&#8221; level, so I&#8217;ve signed up for the beginner track.</p>
<p>I will be posting the commented/explained versions of my scripts to this blog, so I can document the reason I ran things certain ways.  In addition, if time allows, I will attempt to solve the advanced track versions of the events for my own personal educational experience and to figure out if I should go for the advanced track next year.</p>
<p>Wish me luck!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ryanandjeffshow.com/blog/2013/04/21/powershell-scripting-games-2013/feed/</wfw:commentRss>
		<slash:comments>