<?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>Josh Olson&#039;s Blog &#187; PowerShell</title>
	<atom:link href="http://www.jpolson.com/tag/powershell/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.jpolson.com</link>
	<description>A blog about Security, Programming, and System Analysis.</description>
	<lastBuildDate>Tue, 15 Nov 2011 15:47:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Windows PowerShell Execution Policies</title>
		<link>http://www.jpolson.com/20080528/windows-powershell-execution-policies/</link>
		<comments>http://www.jpolson.com/20080528/windows-powershell-execution-policies/#comments</comments>
		<pubDate>Wed, 28 May 2008 17:15:17 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
				<category><![CDATA[Work]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://josh.choosechose.com/20080528/windows-powershell-execution-policies/</guid>
		<description><![CDATA[Windows Powershell sets its Execution Policy to Restricted by default, which states that PowerShell can only be used in interactive mode (no scripts will run.) Use the Get-ExecutionPolicy cmdlet to check which execution policy is currently in-force. $ Get-ExecutionPolicy The following execution policy definitions are from Microsoft&#8217;s website: Restricted – No scripts can be run. [...]]]></description>
			<content:encoded><![CDATA[<p>Windows Powershell sets its Execution Policy to Restricted by default, which states that PowerShell can only be used in interactive mode (no scripts will run.) Use the Get-ExecutionPolicy cmdlet to check which execution policy is currently in-force.</p>
<p><code>$ Get-ExecutionPolicy<br />
</code></p>
<p>The following execution policy definitions are from <a href="http://www.microsoft.com/technet/scriptcenter/topics/msh/cmdlets/get-executionpolicy.mspx">Microsoft&#8217;s website</a>:</p>
<ul>
<li>Restricted – No scripts can be run. Windows PowerShell can be used only in interactive mode.</li>
<li>AllSigned – Only scripts signed by a trusted publisher can be run.</li>
<li>RemoteSigned – Downloaded scripts must be signed by a trusted publisher before they can be run.</li>
<li>Unrestricted – No restrictions; all Windows PowerShell scripts can be run.</li>
</ul>
<p>To change the execution policy, use Set-ExecutionPolicy. The following will enable you to execute all PowerShell scripts.</p>
<p><code>$ Set-ExecutionPolicy Unrestricted</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.jpolson.com/20080528/windows-powershell-execution-policies/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Windows PowerShell &#8211; Recursively delete files and directories modified more than &#8216;n&#8217; days ago.</title>
		<link>http://www.jpolson.com/20080522/windows-powershell-recursively-delete-files-and-directories-modified-more-than-n-days-ago/</link>
		<comments>http://www.jpolson.com/20080522/windows-powershell-recursively-delete-files-and-directories-modified-more-than-n-days-ago/#comments</comments>
		<pubDate>Thu, 22 May 2008 17:25:19 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
				<category><![CDATA[Work]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://josh.choosechose.com/20080522/windows-powershell-recursively-delete-files-and-directories-modified-more-than-n-days-ago/</guid>
		<description><![CDATA[I was recently tasked with writing a script that recursively deletes files and directories modified more than &#8216;n&#8217; days ago &#8211; here&#8217;s the kicker &#8211; using Windows. Many people have accomplished this with long VB Scripts. I was hoping for a much cleaner solution, and decided to try Windows PowerShell . I am quite impressed [...]]]></description>
			<content:encoded><![CDATA[<p>I was recently tasked with writing a script that recursively deletes files and directories modified more than &#8216;n&#8217; days ago &#8211; here&#8217;s the kicker &#8211; using Windows. Many people have accomplished this with long VB Scripts. I was hoping for a much cleaner solution, and decided to try <a href="http://www.microsoft.com/windowsserver2003/technologies/management/powershell/default.mspx">Windows PowerShell</a> . I am quite impressed with Windows Powershell&#8217;s capabilities.</p>
<p>The following script recursively deletes files and directories modified more than 16 days ago.<br />
<code><br />
# prune.ps1<br />
$sticky = (Get-date).AddDays(-16)<br />
$backupDir = "B:\backup"<br />
echo "Recursively deleting files and directories written before $sticky"<br />
Get-ChildItem $backupDir -Recurse | Where-Object { $_.LastWriteTime -lt $sticky } | Remove-Item -Recurse<br />
</code></p>
<p>Note that you can change <code>Remove-Item -Recurse</code> to <code>Remove-Item -Whatif</code> to &#8220;pretend&#8221; to delete files, and display potential deletes on STDOUT. You can also specify <code>Remove-Item -Confirm</code>.</p>
<p>I created a scheduled task that runs a .bat file containing the following:<br />
<code>powershell.exe c:\scripts\prune.ps1 &gt;&gt; c:\scripts\logs\prune.log</code></p>
<p>To watch and or view the output of the script, specify the -noexit switch on the command line.<br />
<code>powershell.exe -noexit c:\scripts\prune.ps1</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.jpolson.com/20080522/windows-powershell-recursively-delete-files-and-directories-modified-more-than-n-days-ago/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

