<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.scriptlore.com/~d/styles/itemcontent.css"?><rss 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/" version="2.0">

<channel>
	<title>ScriptLore</title>
	
	<link>http://scriptlore.com</link>
	<description>All men die, not all men really script</description>
	<lastBuildDate>Wed, 02 Sep 2009 07:21:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.scriptlore.com/Scriptlore" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="scriptlore" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>About Code Signing</title>
		<link>http://scriptlore.com/security/about-code-signing/</link>
		<comments>http://scriptlore.com/security/about-code-signing/#comments</comments>
		<pubDate>Tue, 24 Feb 2009 19:29:13 +0000</pubDate>
		<dc:creator>pogenstad</dc:creator>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[code signing]]></category>
		<category><![CDATA[script signing]]></category>

		<guid isPermaLink="false">http://scriptlore.com/?p=63</guid>
		<description><![CDATA[<p><img class="left" src="http://scriptlore.com/images/sx/2009/i_love_you.jpg" alt="I Love You" /></p>
<p>There was a lot of love going around in May 2000, but as they say love hurts. If organizations would have had some code signing routines in place, the ILOVEYOU virus would have been killed in its crib.</p>
<p>Of course those hippie days are long gone as no one tends to allow .vbs files in the mail server or if it&#8217;s not blocked there the email client should block it.</p>
<p>However code signing can do more than just avoiding the mitigating click, still in this post I won&#8217;t focus on the security benefits of code signing.<br />

<h3>What is code signing (the short version)?</h3>
<p>Code signing is a mechanism where we use public key certificates to sign our code or scripts. What the process does is to add a portion to the file, which can be verified against the certificate which signed it.</p>
<p>Why we would want to do this leads us to the next subject.</p>
<h3>Goals of Code Signing</h3>
<p>In short there are two goals with code signing; <strong>Authenticity</strong> and <strong>Integrity</strong>.</p>
<p>When a script is digitally signed we can look at the signature and find out which digital certificate was used in order to sign the script. Let&#8217;s say we work with Bob, we would very much like to use one of the scripts he has written but based on past experience we don&#8217;t want to run any scripts from our other coworkers.</p>

<p>If Bob has signed the scripts he has created we can look at the signature and verify that the code is authentic. I.e. the script has actually been written by Bob and not by the hotshot whose last script crashed the server. </p>
<p>The second goal is that of integrity, what it means is that the script is still intact or complete. We want to make sure that nothing in the script has changed since Bob signed the script, if it has the script signature has lost its integrity.</p>
<p>So if someone were to edit Bob&#8217;s script it will fail its integrity check when we validate the script signature.</p>
<p>As long as we are able to validate the signature we know that the file was indeed signed by Bob, or technically by Bob&#8217;s certificate.</p>
<h3>Bonus Goal - Non-Repudiation</h3>
<p>The two other goals work in favor for Bob, if something has changed in the code he can just say that the certificate validation failed and at that point he can&#8217;t be held accountable for what the modified code does.</p>
<p>However if the signature is intact and something goes wrong when we run the script Bob can&#8217;t repudiate the fact that he was the one who wrote the script.</p>

<h3>Conclusion</h3>
<p>In a situation where we trust another party, the goals of code signing is to verify that the scripts or code we are about to run are created by a person we trust and that they haven&#8217;t been modified.</p>
<p><em>This post is part of the series <a href="http://scriptlore.com/script-signing-how-to/">How to Implement Code Signing for Scripters</a></em></p>
			]]></description>
			<content:encoded><![CDATA[<p><img class="left" src="http://scriptlore.com/images/sx/2009/i_love_you.jpg" alt="I Love You" /></p>
<p>There was a lot of love going around in May 2000, but as they say love hurts. If organizations would have had some code signing routines in place, the ILOVEYOU virus would have been killed in its crib.</p>
<p>Of course those hippie days are long gone as no one tends to allow .vbs files in the mail server or if it&#8217;s not blocked there the email client should block it.</p>
<p>However code signing can do more than just avoiding the mitigating click, still in this post I won&#8217;t focus on the security benefits of code signing.<br />
<span id="more-63"></span></p>
<h3>What is code signing (the short version)?</h3>
<p>Code signing is a mechanism where we use public key certificates to sign our code or scripts. What the process does is to add a portion to the file, which can be verified against the certificate which signed it.</p>
<p>Why we would want to do this leads us to the next subject.</p>
<h3>Goals of Code Signing</h3>
<p>In short there are two goals with code signing; <strong>Authenticity</strong> and <strong>Integrity</strong>.</p>
<p>When a script is digitally signed we can look at the signature and find out which digital certificate was used in order to sign the script. Let&#8217;s say we work with Bob, we would very much like to use one of the scripts he has written but based on past experience we don&#8217;t want to run any scripts from our other coworkers.</p>
<p>If Bob has signed the scripts he has created we can look at the signature and verify that the code is authentic. I.e. the script has actually been written by Bob and not by the hotshot whose last script crashed the server. </p>
<p>The second goal is that of integrity, what it means is that the script is still intact or complete. We want to make sure that nothing in the script has changed since Bob signed the script, if it has the script signature has lost its integrity.</p>
<p>So if someone were to edit Bob&#8217;s script it will fail its integrity check when we validate the script signature.</p>
<p>As long as we are able to validate the signature we know that the file was indeed signed by Bob, or technically by Bob&#8217;s certificate.</p>
<h3>Bonus Goal &#8211; Non-Repudiation</h3>
<p>The two other goals work in favor for Bob, if something has changed in the code he can just say that the certificate validation failed and at that point he can&#8217;t be held accountable for what the modified code does.</p>
<p>However if the signature is intact and something goes wrong when we run the script Bob can&#8217;t repudiate the fact that he was the one who wrote the script.</p>
<h3>Conclusion</h3>
<p>In a situation where we trust another party, the goals of code signing is to verify that the scripts or code we are about to run are created by a person we trust and that they haven&#8217;t been modified.</p>
<p><em>This post is part of the series <a href="http://scriptlore.com/script-signing-how-to/">How to Implement Code Signing for Scripters</a></em></p>
]]></content:encoded>
			<wfw:commentRss>http://scriptlore.com/security/about-code-signing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Debug, Parameter</title>
		<link>http://scriptlore.com/powershell/debug/</link>
		<comments>http://scriptlore.com/powershell/debug/#comments</comments>
		<pubDate>Tue, 30 Sep 2008 13:48:58 +0000</pubDate>
		<dc:creator>pogenstad</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Basics]]></category>
		<category><![CDATA[Parameters]]></category>

		<guid isPermaLink="false">http://scriptlore.com/?p=16</guid>
		<description><![CDATA[This article is eagerly awaiting to be written (honestly)!]]></description>
			<content:encoded><![CDATA[<p><img class="left" src="http://scriptlore.com/images/sx/2008/powershell-parameter-debug.jpg" alt="PowerShell Debug Parameter" /></p>
<p>This article is eagerly awaiting to be written (honestly)!<br />
<span id="more-16"></span></p>
]]></content:encoded>
			<wfw:commentRss>http://scriptlore.com/powershell/debug/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Verbose, Parameter</title>
		<link>http://scriptlore.com/powershell/verbose/</link>
		<comments>http://scriptlore.com/powershell/verbose/#comments</comments>
		<pubDate>Mon, 28 Jul 2008 05:53:17 +0000</pubDate>
		<dc:creator>pogenstad</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Basics]]></category>
		<category><![CDATA[Parameters]]></category>

		<guid isPermaLink="false">http://scriptlore.com/?p=39</guid>
		<description><![CDATA[Some cmdlets can provide verbose data. This is disabled by default but can be enabled by using the -Verbose parameter. This can be useful if you want to log an action or troubleshoot your scripts. To view an example of this we will look at the Set-Alias cmdlet: PS C:\&#62; Set-Alias Time Get-Date -Verbose VERBOSE: [...]]]></description>
			<content:encoded><![CDATA[<p><img class="left" src="http://scriptlore.com/images/sx/2008/powershell-parameter-verbose.jpg" alt="PowerShell Verbose Parameter" /></p>
<p>Some cmdlets can provide verbose data. This is disabled by default but can be enabled by using the -Verbose parameter. This can be useful if you want to log an action or troubleshoot your scripts.<br />
<span id="more-39"></span><br />
To view an example of this we will look at the Set-Alias cmdlet:</p>
<p><code>PS C:\&gt; Set-Alias Time Get-Date -Verbose<br />
VERBOSE: Performing operation "Set Alias" on Target "Name: Time Value: Get-Date".<br />
PS C:\&gt;</code></p>
<p>As I said some cmdlets doesn&#8217;t provide verbose information so if we use the parameter with the Get-Date cmdlet it doesn&#8217;t provide any additional verbose data:</p>
<p><code>PS C:\&gt; Get-Date -Verbose</code></p>
<p><code>Monday, July 28, 2008 7:48:33 AM<br />
PS C:\&gt;</code></p>
<p>Generally you will find that the Verbose parameter works on PowerShell cmdlets that make some kind of change to the system.</p>
]]></content:encoded>
			<wfw:commentRss>http://scriptlore.com/powershell/verbose/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>OutBuffer, Parameter</title>
		<link>http://scriptlore.com/powershell/outbuffer/</link>
		<comments>http://scriptlore.com/powershell/outbuffer/#comments</comments>
		<pubDate>Mon, 28 Jul 2008 05:16:27 +0000</pubDate>
		<dc:creator>pogenstad</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Basics]]></category>
		<category><![CDATA[Parameters]]></category>

		<guid isPermaLink="false">http://scriptlore.com/?p=20</guid>
		<description><![CDATA[The OutBuffer parameter determines how many objects will be buffered before calling the next cmdlet in the pipeline. Instead of typing out -OutBuffer you can use -ob for short. I will add more information to this page when I&#8217;ve used OutBuffer more and can provide some examples.]]></description>
			<content:encoded><![CDATA[<p><img class="left" src="http://scriptlore.com/images/sx/2008/powershell-parameter-outbuffer.jpg" alt="PowerShell OutBuffer Parameter" /></p>
<p>The OutBuffer parameter determines how many objects will be buffered before calling the next cmdlet in the pipeline.</p>
<p>Instead of typing out -OutBuffer you can use -ob for short.<br />
<span id="more-20"></span><br />
I will add more information to this page when I&#8217;ve used OutBuffer more and can provide some examples.</p>
]]></content:encoded>
			<wfw:commentRss>http://scriptlore.com/powershell/outbuffer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ErrorAction, Parameter</title>
		<link>http://scriptlore.com/powershell/erroraction/</link>
		<comments>http://scriptlore.com/powershell/erroraction/#comments</comments>
		<pubDate>Mon, 09 Jun 2008 09:07:48 +0000</pubDate>
		<dc:creator>pogenstad</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Basics]]></category>
		<category><![CDATA[Parameters]]></category>

		<guid isPermaLink="false">http://scriptlore.com/?p=17</guid>
		<description><![CDATA[<p><img class="left" src="http://scriptlore.com/images/sx/2008/powershell-parameter-erroraction.jpg" alt="PowerShell ErrorAction Parameter" /></p>
<p>Like many other aspects of PowerShell, -ErrorAction kind of explains itself when you think of it. Basically it instructs PowerShell what action to take when an error occurs. The actions you can set are Continue (which is default), Stop, SilentlyContinue and Inquire. Let&#8217;s take a look.</p>
<h3>Continue</h3>
<p>You can verify that Continue is the default action by looking at the $ErrorActionPreference variable. We&#8217;ll be using the Stop-Process Cmdlet to test this.</p>

<p><code>PS C:\&#62; $ErrorActionPreference<br />
Continue<br />
PS C:\&#62; Stop-Process 206,304<br />
Stop-Process : Cannot find a process with the process identifier 206.<br />
At line:1 char:13<br />
+ Stop-Process  &#60;&#60;&#60;&#60; 206,304<br />

Stop-Process : Cannot find a process with the process identifier 304.<br />
At line:1 char:13<br />
+ Stop-Process  &#60;&#60;&#60;</code></p>
<p>Since we know continue is the default error action we don&#8217;t need to use &#8220;-ErrorAction Continue&#8221;.</p>
<h3>Stop</h3>
<p>The Stop error action instructs PowerShell to stop executing after the first error.</p>
<p><code>PS C:\&#62; Stop-Process 206,304 -ErrorAction Stop<br />

Stop-Process : Command execution stopped because the shell variable "ErrorActionPreference" is set to Stop: Cannot find<br />
 a process with the process identifier 206.<br />
At line:1 char:13<br />
+ Stop-Process  &#60;&#60;&#60; </code></p>
<p>Compared to when we used &#8220;Continue&#8221;, PowerShell will only try to stop the process with id 206 and never move on to 304 since it failed to stop the first one.</p>
<h3>SilentlyContinue</h3>
<p>As you might guess SilentlyContinue acts like Continue with the exception that we don&#8217;t see the errors. To save some typing we don&#8217;t need to write out ErrorAction, we can use EA for short.</p>

<p><code>PS C:\&#62; Stop-Process 206,304 -EA SilentlyContinue<br />
PS C:\&#62;</code></p>
<h3>Inquire</h3>
<p>Inquire informs us that there has been an error and lets us decide what to do.</p>
<p><code>PS C:\&#62; Stop-Process 206,304 -EA Inquire</code></p>
<p><code>Confirm<br />
Cannot find a process with the process identifier 206.<br />

[Y] Yes  [A] Yes to All  [H] Halt Command  [S] Suspend  [?] Help (default is &#34;Y&#34;): h<br />
Stop-Process : Command execution stopped because the user selected the Halt option.<br />
At line:1 char:13<br />
+ Stop-Process  &#60;&#60;&#60;</code></p>]]></description>
			<content:encoded><![CDATA[<p><img class="left" src="http://scriptlore.com/images/sx/2008/powershell-parameter-erroraction.jpg" alt="PowerShell ErrorAction Parameter" /></p>
<p>Like many other aspects of PowerShell, -ErrorAction kind of explains itself when you think of it. Basically it instructs PowerShell what action to take when an error occurs. The actions you can set are Continue (which is default), Stop, SilentlyContinue and Inquire. Let&#8217;s take a look.<span id="more-17"></span></p>
<h3>Continue</h3>
<p>You can verify that Continue is the default action by looking at the $ErrorActionPreference variable. We&#8217;ll be using the Stop-Process Cmdlet to test this.</p>
<p><code>PS C:\&gt; $ErrorActionPreference<br />
Continue<br />
PS C:\&gt; Stop-Process 206,304<br />
Stop-Process : Cannot find a process with the process identifier 206.<br />
At line:1 char:13<br />
+ Stop-Process  &lt;&lt;&lt;&lt; 206,304<br />
Stop-Process : Cannot find a process with the process identifier 304.<br />
At line:1 char:13<br />
+ Stop-Process  &lt;&lt;&lt;</code></p>
<p>Since we know continue is the default error action we don&#8217;t need to use &#8220;-ErrorAction Continue&#8221;.</p>
<h3>Stop</h3>
<p>The Stop error action instructs PowerShell to stop executing after the first error.</p>
<p><code>PS C:\&gt; Stop-Process 206,304 -ErrorAction Stop<br />
Stop-Process : Command execution stopped because the shell variable "ErrorActionPreference" is set to Stop: Cannot find<br />
 a process with the process identifier 206.<br />
At line:1 char:13<br />
+ Stop-Process  &lt;&lt;&lt; </code></p>
<p>Compared to when we used &#8220;Continue&#8221;, PowerShell will only try to stop the process with id 206 and never move on to 304 since it failed to stop the first one.</p>
<h3>SilentlyContinue</h3>
<p>As you might guess SilentlyContinue acts like Continue with the exception that we don&#8217;t see the errors. To save some typing we don&#8217;t need to write out ErrorAction, we can use EA for short.</p>
<p><code>PS C:\&gt; Stop-Process 206,304 -EA SilentlyContinue<br />
PS C:\&gt;</code></p>
<h3>Inquire</h3>
<p>Inquire informs us that there has been an error and lets us decide what to do.</p>
<p><code>PS C:\&gt; Stop-Process 206,304 -EA Inquire</code></p>
<p><code>Confirm<br />
Cannot find a process with the process identifier 206.<br />
[Y] Yes  [A] Yes to All  [H] Halt Command  [S] Suspend  [?] Help (default is &quot;Y&quot;): h<br />
Stop-Process : Command execution stopped because the user selected the Halt option.<br />
At line:1 char:13<br />
+ Stop-Process  &lt;&lt;&lt;</code></p>
]]></content:encoded>
			<wfw:commentRss>http://scriptlore.com/powershell/erroraction/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WhatIf, Parameter</title>
		<link>http://scriptlore.com/powershell/whatif/</link>
		<comments>http://scriptlore.com/powershell/whatif/#comments</comments>
		<pubDate>Mon, 26 May 2008 15:59:24 +0000</pubDate>
		<dc:creator>pogenstad</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Basics]]></category>
		<category><![CDATA[Parameters]]></category>

		<guid isPermaLink="false">http://scriptlore.com/?p=21</guid>
		<description><![CDATA[<p><img class="left" src="http://scriptlore.com/images/sx/2008/powershell-parameter-whatif.jpg" alt="PowerShell WhatIf Parameter" /></p>
<p>What if you just deleted 5000 accounts from your active directory domain by accident, what if there had been an easy way to make sure you were doing the right thing before the deletion. Would you have wanted to use it? I know I would. Just imagine you were planning on deleting all accounts which had been disabled for six months but you forgot some important switch and most of your accounts were gone because of that stupid switch. Ok, so this might be a bit far fetched but these things can happen and if you are not 100 percent sure of what you are doing, it&#8217;s great to be able to see what the results of your actions will be before you take them.</p>
<p>Let&#8217;s say we&#8217;ve been taking random notes and just want to kill all notepad processes without having to choose if we want to save every single file. Working with the Get-Process, Where-Object and Stop-Process cmdlets we decide to kill all the processes which has &#8220;note&#8221; in them.</p>

<p><code>PS C:\&#62; Get-Process &#124; Where-Object {$_.ProcessName -match "note"} &#124; Stop-Process -Whatif<br />
What if: Performing operation "Stop-Process" on Target "notepad (4284)".<br />
What if: Performing operation "Stop-Process" on Target "notepad (4524)".<br />
What if: Performing operation "Stop-Process" on Target "notepad (4848)".<br />
What if: Performing operation "Stop-Process" on Target "notepad++ (4684)".<br />
What if: Performing operation "Stop-Process" on Target "ONENOTE (5944)".<br />
What if: Performing operation "Stop-Process" on Target "ONENOTEM (3876)".<br />
PS C:\&#62;</code></p>

<p>This would have wiped out every instance of notepad.exe along with my Onenote and notepad++ processes which was not what I wanted.</p>
<h3>Lame example?</h3>
<p>Yes, I guess you&#8217;re right that was quite a lame example. However I think it does illustrate how you can use the -whatif parameter. It can be very useful if you are working with important data and don&#8217;t want to make mistakes. Also it&#8217;s useful if your just playing around with PowerShell and learning what all the fuss is about.</p>
]]></description>
			<content:encoded><![CDATA[<p><img class="left" src="http://scriptlore.com/images/sx/2008/powershell-parameter-whatif.jpg" alt="PowerShell WhatIf Parameter" /></p>
<p>What if you just deleted 5000 accounts from your active directory domain by accident, what if there had been an easy way to make sure you were doing the right thing before the deletion. Would you have wanted to use it? I know I would. Just imagine you were planning on deleting all accounts which had been disabled for six months but you forgot some important switch and most of your accounts were gone because of that stupid switch.<br />
<span id="more-21"></span><br />
Ok, so this might be a bit far fetched but these things can happen and if you are not 100 percent sure of what you are doing, it&#8217;s great to be able to see what the results of your actions will be before you take them.</p>
<p>Let&#8217;s say we&#8217;ve been taking random notes and just want to kill all notepad processes without having to choose if we want to save every single file. Working with the Get-Process, Where-Object and Stop-Process cmdlets we decide to kill all the processes which has &#8220;note&#8221; in them.</p>
<p><code>PS C:\&gt; Get-Process | Where-Object {$_.ProcessName -match "note"} | Stop-Process -Whatif<br />
What if: Performing operation "Stop-Process" on Target "notepad (4284)".<br />
What if: Performing operation "Stop-Process" on Target "notepad (4524)".<br />
What if: Performing operation "Stop-Process" on Target "notepad (4848)".<br />
What if: Performing operation "Stop-Process" on Target "notepad++ (4684)".<br />
What if: Performing operation "Stop-Process" on Target "ONENOTE (5944)".<br />
What if: Performing operation "Stop-Process" on Target "ONENOTEM (3876)".<br />
PS C:\&gt;</code></p>
<p>This would have wiped out every instance of notepad.exe along with my Onenote and notepad++ processes which was not what I wanted.</p>
<h3>Lame example?</h3>
<p>Yes, I guess you&#8217;re right that was quite a lame example. However I think it does illustrate how you can use the -whatif parameter. It can be very useful if you are working with important data and don&#8217;t want to make mistakes. Also it&#8217;s useful if your just playing around with PowerShell and learning what all the fuss is about.</p>
]]></content:encoded>
			<wfw:commentRss>http://scriptlore.com/powershell/whatif/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ErrorVariable, Parameter</title>
		<link>http://scriptlore.com/powershell/errorvariable/</link>
		<comments>http://scriptlore.com/powershell/errorvariable/#comments</comments>
		<pubDate>Mon, 26 May 2008 15:15:51 +0000</pubDate>
		<dc:creator>pogenstad</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Basics]]></category>
		<category><![CDATA[Parameters]]></category>

		<guid isPermaLink="false">http://scriptlore.com/?p=18</guid>
		<description><![CDATA[<p><img class="left" src="http://scriptlore.com/images/sx/2008/powershell-parameter-errorvariable.jpg" alt="PowerShell ErrorVariable Parameter" /></p>
<p>It is said that we learn from our mistakes, and that to improve learning it&#8217;s best to write things down. How about storing our mistakes and errors in a variable? If that&#8217;s not killing two flies with one stone, at least it&#8217;s a useful feature of PowerShell. Let&#8217;s use it and see how it works, using the Stop-Service cmdlet we try to stop a service:</p>

<p><code>PS C:\&#62; Stop-Service -name XAudioService -ErrorVariable myErrors<br />
Stop-Service : Service 'XAudioService (XAudioService)' cannot be stopped due to the following error: Cannot open XAudio<br />
Service service on computer '.'.<br />
At line:1 char:13<br />
+ Stop-Service  &#60;&#60;&#60;</code></p>
<p>As you can see the error is also written to screen. From now on we can reference the error in the $myErrors variable we created:</p>
<p><code>PS C:\&#62; $myErrors<br />

Stop-Service : Service 'XAudioService (XAudioService)' cannot be stopped due to the following error: Cannot open XAudio<br />
Service service on computer '.'.<br />
At line:1 char:13<br />
+ Stop-Service  &#60;&#60;&#60;</code></p>
<p>You might want to know that even if you don&#8217;t specify the -ErrorVariable parameter all the errors will be storied in a special error called $error.</p>
<p>Saving the error variable like we have done above will ensure that you have the last error saved. One thing you can do is to add a plus sign before the variable when you want to append to the error variable. Here is an example:</p>
<p><code>PS C:\&#62; Stop-Service -name XAudioService -ErrorVariable +myError<br />

PS C:\&#62; Stop-Service -name WinRM -ErrorVariable +myError<br />
PS C:\&#62; $myError.Count<br />
2<br />
PS C:\&#62;</code></p>]]></description>
			<content:encoded><![CDATA[<p><img class="left" src="http://scriptlore.com/images/sx/2008/powershell-parameter-errorvariable.jpg" alt="PowerShell ErrorVariable Parameter" /></p>
<p>It is said that we learn from our mistakes, and that to improve learning it&#8217;s best to write things down. How about storing our mistakes and errors in a variable? If that&#8217;s not killing two flies with one stone, at least it&#8217;s a useful feature of PowerShell. Let&#8217;s use it and see how it works, using the Stop-Service cmdlet we try to stop a service: <span id="more-18"></span></p>
<p><code>PS C:\&gt; Stop-Service -name XAudioService -ErrorVariable myErrors<br />
Stop-Service : Service 'XAudioService (XAudioService)' cannot be stopped due to the following error: Cannot open XAudio<br />
Service service on computer '.'.<br />
At line:1 char:13<br />
+ Stop-Service  &lt;&lt;&lt;</code></p>
<p>As you can see the error is also written to screen. From now on we can reference the error in the $myErrors variable we created:</p>
<p><code>PS C:\&gt; $myErrors<br />
Stop-Service : Service 'XAudioService (XAudioService)' cannot be stopped due to the following error: Cannot open XAudio<br />
Service service on computer '.'.<br />
At line:1 char:13<br />
+ Stop-Service  &lt;&lt;&lt;</code></p>
<p>You might want to know that even if you don&#8217;t specify the -ErrorVariable parameter all the errors will be storied in a special error called $error.</p>
<p>Saving the error variable like we have done above will ensure that you have the last error saved. One thing you can do is to add a plus sign before the variable when you want to append to the error variable. Here is an example:</p>
<p><code>PS C:\&gt; Stop-Service -name XAudioService -ErrorVariable +myError<br />
PS C:\&gt; Stop-Service -name WinRM -ErrorVariable +myError<br />
PS C:\&gt; $myError.Count<br />
2<br />
PS C:\&gt;</code></p>
]]></content:encoded>
			<wfw:commentRss>http://scriptlore.com/powershell/errorvariable/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Confirm, Parameter</title>
		<link>http://scriptlore.com/powershell/confirm/</link>
		<comments>http://scriptlore.com/powershell/confirm/#comments</comments>
		<pubDate>Wed, 21 May 2008 14:34:35 +0000</pubDate>
		<dc:creator>pogenstad</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Basics]]></category>
		<category><![CDATA[Parameters]]></category>

		<guid isPermaLink="false">http://scriptlore.com/?p=15</guid>
		<description><![CDATA[<img class="left" src="http://scriptlore.com/images/sx/2008/powershell-parameter-confirm.jpg" alt="PowerShell Confirm Parameter" />

Imagine you are feeling handy and start out to rebuild your bathroom. Now imagine you're standing knee deep in water in your basement. I bet you wished that somewhere in your head there was a tiny voice which had asked you, "do you <em>really</em> want to drill there"? This is the purpose of the PowerShell -Confirm parameter. If you're running a cmdlet which changes the system state you can use -Confirm in order to get a question asking you if you really want to go ahead with the change.

<h3>Argh, my files, my precious files!</h3>

We've all heard horror stories of format c: and the like. At one point you might even have deleted files by mistake. With the Remove-Item cmdlet you can do just that.

<code>PS C:\Temp&#62; Remove-Item *
PS C:\Temp&#62;</code> &#60;- That went smooth!

However wouldn't this have been better:

<code>PS C:\Temp&#62; Remove-Item * -Confirm</code>

<code>Confirm
Are you sure you want to perform this action?
Performing operation "Remove File" on Target "C:\Temp\junkfile1.txt".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is &#34;Y&#34;): y</code>

<code>Confirm
Are you sure you want to perform this action?
Performing operation "Remove File" on Target "C:\Temp\junkfile2.txt".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is &#34;Y&#34;): y</code>

<code>Confirm
Are you sure you want to perform this action?
Performing operation "Remove File" on Target "C:\Temp\junkfile3.txt".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is &#34;Y&#34;): y</code>

<code>Confirm
Are you sure you want to perform this action?
Performing operation "Remove File" on Target "C:\Temp\single-copy-of-expense-report.xlsx".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is &#34;Y&#34;): n</code>

<h3>Lessons Learned</h3>

As the carpenters say; measure twice, cut once. Sometimes it's better to step carefully unless you are really sure of what you are doing. The -Confirm parameter can be that little voice inside your head.]]></description>
			<content:encoded><![CDATA[<p><img class="left" src="http://scriptlore.com/images/sx/2008/powershell-parameter-confirm.jpg" alt="PowerShell Confirm Parameter" /></p>
<p>Imagine you are feeling handy and start out to rebuild your bathroom. Now imagine you&#8217;re standing knee deep in water in your basement. I bet you wished that somewhere in your head there was a tiny voice which had asked you, &#8220;do you <em>really</em> want to drill there&#8221;? This is the purpose of the PowerShell -Confirm parameter. If you&#8217;re running a cmdlet which changes the system state you can use -Confirm in order to get a question asking you if you really want to go ahead with the change.<br />
<span id="more-15"></span></p>
<h3>Argh, my files, my precious files!</h3>
<p>We&#8217;ve all heard horror stories of format c: and the like. At one point you might even have deleted files by mistake. With the Remove-Item cmdlet you can do just that.</p>
<p><code>PS C:\Temp&gt; Remove-Item *<br />
PS C:\Temp&gt;</code> &lt;- That went smooth!</p>
<p>However wouldn&#8217;t this have been better:</p>
<p><code>PS C:\Temp&gt; Remove-Item * -Confirm</code></p>
<p><code>Confirm<br />
Are you sure you want to perform this action?<br />
Performing operation "Remove File" on Target "C:\Temp\junkfile1.txt".<br />
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is &quot;Y&quot;): y</code></p>
<p><code>Confirm<br />
Are you sure you want to perform this action?<br />
Performing operation "Remove File" on Target "C:\Temp\junkfile2.txt".<br />
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is &quot;Y&quot;): y</code></p>
<p><code>Confirm<br />
Are you sure you want to perform this action?<br />
Performing operation "Remove File" on Target "C:\Temp\junkfile3.txt".<br />
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is &quot;Y&quot;): y</code></p>
<p><code>Confirm<br />
Are you sure you want to perform this action?<br />
Performing operation "Remove File" on Target "C:\Temp\single-copy-of-expense-report.xlsx".<br />
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is &quot;Y&quot;): n</code></p>
<h3>Lessons Learned</h3>
<p>As the carpenters say; measure twice, cut once. Sometimes it&#8217;s better to step carefully unless you are really sure of what you are doing. The -Confirm parameter can be that little voice inside your head.</p>
]]></content:encoded>
			<wfw:commentRss>http://scriptlore.com/powershell/confirm/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>OutVariable, Parameter</title>
		<link>http://scriptlore.com/powershell/outvariable/</link>
		<comments>http://scriptlore.com/powershell/outvariable/#comments</comments>
		<pubDate>Mon, 19 May 2008 21:30:18 +0000</pubDate>
		<dc:creator>pogenstad</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Basics]]></category>
		<category><![CDATA[Parameters]]></category>

		<guid isPermaLink="false">http://scriptlore.com/?p=19</guid>
		<description><![CDATA[Building on the Perl motto; &#8220;There&#8217;s more than one way to do it&#8221;, PowerShell lovers will tell you that they can play too. Basically the -OutVariable parameter stores the output from a cmdlet to a variable and at the same time letting the cmdlet display all the output to the screen. For example looking at [...]]]></description>
			<content:encoded><![CDATA[<p><img class="left" src="http://scriptlore.com/images/sx/2008/powershell-parameter-outvariable.jpg" alt="PowerShell OutVariable Parameter" /></p>
<p>Building on the Perl motto; &#8220;There&#8217;s more than one way to do it&#8221;, PowerShell lovers will tell you that they can play too. Basically the -OutVariable parameter stores the output from a cmdlet to a variable and at the same time letting the cmdlet display all the output to the screen. For example looking at the Get-ChildItem cmdlet you can store the output in a variable by doing:</p>
<p><span id="more-19"></span><code>$myChildren = Get-ChildItem</code></p>
<p>Using the -OutVariable parameter you would instead type:</p>
<p><code>Get-ChildItem -OutVariable myChildren</code></p>
<p>This would also store the output in the myChildren variable (notice the lack of the $ sign), but unlike the first example the output would be printed to the screen. </p>
<p>This might sound a lot like the Tee-Object cmdlet. However you can also use OutVariable like this:</p>
<p><code>Get-ChildItem Directory1 -OutVariable myChildren<br />
Get-ChildItem Directory2 -OutVariable +myChildren</code></p>
<p>This way the $myChildren variable would hold the contents of both Directory1 and Directory2. Another difference, if you&#8217;re in a hurry and want to juice out some performance, can be shown by the Measure-Command cmdlet.</p>
<p><code>Measure-Command {Get-ChildItem | Tee-Object -variable myTeeOutput}<br />
TotalMilliseconds : 3,3151</code></p>
<p><code>Measure-Command {Get-ChildItem -OutVariable myOutVariableOutput}<br />
TotalMilliseconds : 2,0668</code></p>
<p>Folks, we have a winner! But what will we do with all the extra free time?</p>
<p>If you just want to store the variable and not display the output you can use the Out-Null cmdlet:</p>
<p><code>Get-ChildItem -OutVariable myChildren | Out-Null</code></p>
]]></content:encoded>
			<wfw:commentRss>http://scriptlore.com/powershell/outvariable/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Get-ExecutionPolicy</title>
		<link>http://scriptlore.com/powershell/get-executionpolicy/</link>
		<comments>http://scriptlore.com/powershell/get-executionpolicy/#comments</comments>
		<pubDate>Wed, 07 May 2008 21:51:01 +0000</pubDate>
		<dc:creator>pogenstad</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Basics]]></category>
		<category><![CDATA[Cmdlet]]></category>
		<category><![CDATA[Native]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://scriptlore.com/?p=5</guid>
		<description><![CDATA[PowerShell uses for different settings called Execution Policy which governs how scripts will run on your computer and if they need to be digitally signed. Get-ExecutionPolicy is a Cmdlet which allows you to view which Execution Policy that is currently used by your computer. SYNTAX Get-ExecutionPolicy -Verbose -Debug -ErrorAction -ErrorVariable -OutVariable Examples PS C:\&#62; Get-ExecutionPolicy [...]]]></description>
			<content:encoded><![CDATA[<p><img class="left" src="http://scriptlore.com/images/sx/2008/cmdlet-get-executionpolicy.jpg" alt="Get-ExecutionPolicy" /></p>
<p>PowerShell uses for different settings called <a href="http://scriptlore.com/powershell/execution-policy/" title="PowerShell Execution Policy">Execution Policy</a> which governs how scripts will run on your computer and if they need to be digitally signed. Get-ExecutionPolicy is a Cmdlet which allows you to view which Execution Policy that is currently used by your computer. <span id="more-5"></span> </p>
<h3>SYNTAX</h3>
<p>Get-ExecutionPolicy<br />
<a href="http://scriptlore.com/powershell/verbose/">-Verbose</a><br />
<a href="http://scriptlore.com/powershell/debug/">-Debug</a><br />
<a href="http://scriptlore.com/powershell/erroraction/" title="PowerShell ErrorAction Parameter">-ErrorAction</a><br />
<a href="http://scriptlore.com/powershell/errorvariable/" title="PowerShell ErrorVariable Parameter">-ErrorVariable</a><br />
<a href="http://scriptlore.com/powershell/outvariable/" title="PowerShell OutVariable Parameter">-OutVariable</a></p>
<h3>Examples</h3>
<p>PS C:\&gt; Get-ExecutionPolicy<br />
Restricted</p>
]]></content:encoded>
			<wfw:commentRss>http://scriptlore.com/powershell/get-executionpolicy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
