<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Speaking of which... : PowerShell</title><link>http://blogs.msdn.com/johan/archive/tags/PowerShell/default.aspx</link><description>Tags: PowerShell</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Running a scheduled PowerShell script on a pre-Vista OS</title><link>http://blogs.msdn.com/johan/archive/2009/03/05/running-a-scheduled-powershell-script-on-a-pre-vista-os.aspx</link><pubDate>Thu, 05 Mar 2009 13:00:50 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9459530</guid><dc:creator>JohanS</dc:creator><slash:comments>3</slash:comments><comments>http://blogs.msdn.com/johan/comments/9459530.aspx</comments><wfw:commentRss>http://blogs.msdn.com/johan/commentrss.aspx?PostID=9459530</wfw:commentRss><description>&lt;p&gt;It's been fun to see the reception that PowerShell has gotten. People are using it for tons of different stuff and the ingenuity in some of the scenarios is quite impressive. There is one thing, however, that you should be aware of. PowerShell is not an ideal candidate for execution through the Task Scheduler.&lt;/p&gt;  &lt;h1&gt;Problem&lt;/h1&gt;  &lt;p&gt;A long-running PowerShell script is being executed using the Task Scheduler. At apparently random intervals the script will fail with a &lt;span class="InlineCode"&gt;System.Management.Automation.PipelineStoppedException&lt;/span&gt;.&lt;/p&gt;  &lt;h1&gt;Cause&lt;/h1&gt;  &lt;p&gt;Looking up the exception on &lt;a href="http://msdn.microsoft.com/en-us/library/system.management.automation.pipelinestoppedexception(VS.85).aspx" target="_blank"&gt;MSDN&lt;/a&gt; might not shed any light on the situation unless you know what is happening.&lt;/p&gt;  &lt;p&gt;&lt;em&gt;The exception thrown when a cmdlet or a Windows PowerShell provider attempts to write to the pipeline or perform a number of other Windows PowerShell operations after the pipeline has been terminated. The pipeline could have been terminated before the call was made or during the call.&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;When the Task Scheduler executes a PowerShell script it needs to use the .NET Framework. When running the .NET Framework it uses the console session (Session 0). This problem occurs when someone is logged on to the root console (either physically or using Terminal Services) and logs off &lt;em&gt;while the script is executing&lt;/em&gt;.&lt;/p&gt;  &lt;h1&gt;Repro&lt;/h1&gt;  &lt;p&gt;You can easily reproduce this by creating a small script that sleeps for a while. Schedule the script to run immediately and then log off. To illustrate I've used the following script:&lt;/p&gt;  &lt;div class="SampleCode"&gt;function Main()    &lt;br /&gt;{     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Start-Transcript &amp;quot;C:\Test\Psjob.txt&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; 'Start-Sleep'     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Start-Sleep (2*60)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; 'Ready'     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Stop-Transcript     &lt;br /&gt;}     &lt;br /&gt;&amp;#160; &lt;br /&gt;Main&lt;/div&gt;  &lt;p&gt;When correctly executed this script will generate a transcript that looks like this:&lt;/p&gt;  &lt;div class="DebugSample"&gt;**********************    &lt;br /&gt;Windows PowerShell Transcript Start     &lt;br /&gt;Start time: 20090305111600     &lt;br /&gt;Username&amp;#160; : DOMAIN\SYSTEM     &lt;br /&gt;Machine&amp;#160;&amp;#160; : MACHINENAME (Microsoft Windows NT 5.2.3790 Service Pack 2)     &lt;br /&gt;**********************     &lt;br /&gt;Transcript started, output file is C:\Test\Psjob.txt     &lt;br /&gt;Start-Sleep     &lt;br /&gt;Ready     &lt;br /&gt;**********************     &lt;br /&gt;Windows PowerShell Transcript End     &lt;br /&gt;End time: 20090305111800     &lt;br /&gt;**********************&lt;/div&gt;  &lt;p&gt;However, if I log off the console while the script is executing I get the following transcript:&lt;/p&gt;  &lt;div class="DebugSample"&gt;**********************    &lt;br /&gt;Windows PowerShell Transcript Start     &lt;br /&gt;Start time: 20090305114300     &lt;br /&gt;Username&amp;#160; : DOMAIN\SYSTEM     &lt;br /&gt;Machine&amp;#160;&amp;#160; : MACHINENAME (Microsoft Windows NT 5.2.3790 Service Pack 2)     &lt;br /&gt;**********************     &lt;br /&gt;Transcript started, output file is C:\Test\Psjob.txt     &lt;br /&gt;Start-Sleep     &lt;br /&gt;**********************     &lt;br /&gt;Windows PowerShell Transcript End     &lt;br /&gt;End time: 20090305114340     &lt;br /&gt;**********************&lt;/div&gt;  &lt;p&gt;As you can see the transcript is properly ended as PowerShell shuts down, but if you look at the output in the middle you'll see that we never write &amp;quot;Ready&amp;quot; to the file. This is because the script was prematurely terminated.&lt;/p&gt;  &lt;h1&gt;Resolution&lt;/h1&gt;  &lt;p&gt;The quick and easy resolution is to upgrade to Vista, Windows Server 2008 or later, since as of Windows Vista the console session is no longer running in Session 0.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9459530" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/johan/archive/tags/Misc/default.aspx">Misc</category><category domain="http://blogs.msdn.com/johan/archive/tags/PowerShell/default.aspx">PowerShell</category></item><item><title>PowerShell - Managing Feature Delegation in IIS7</title><link>http://blogs.msdn.com/johan/archive/2008/12/16/powershell-managing-feature-delegation-in-iis7.aspx</link><pubDate>Tue, 16 Dec 2008 16:51:54 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9225881</guid><dc:creator>JohanS</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/johan/comments/9225881.aspx</comments><wfw:commentRss>http://blogs.msdn.com/johan/commentrss.aspx?PostID=9225881</wfw:commentRss><description>&lt;p&gt;Perhaps you've read my earlier post on &lt;a href="http://blogs.msdn.com/johan/archive/2008/10/02/powershell-advanced-configuration-editing-in-iis7.aspx"&gt;advanced feature delegation&lt;/a&gt; using PowerShell and the &lt;a href="http://learn.iis.net/page.aspx/429/installing-the-iis-70-powershell-provider/"&gt;IIS 7.0 PowerShell Provider&lt;/a&gt;. This could actually be called Part II.&lt;/p&gt;  &lt;p&gt;The previous post was based on a quick question from a premier customer. He is a never-ending source of intriguing questions and I always enjoy his &amp;quot;just one thing&amp;quot;-type of inquiries. They often force you to think a little extra. Anyway, the other day he came with a question, which (as always) seemed simple enough at a first glance. The goal was to set Feature Delegation for SMTP E-mail And Forms Authentication to &amp;quot;Read Only&amp;quot;.&lt;/p&gt;  &lt;p&gt;&lt;img src="http://blogs.msdn.com/photos/johan/images/9225741/original.aspx" /&gt; &lt;/p&gt;  &lt;p&gt;Now, most basic configuration topics have been covered in countless posts, and at first I thought that this shouldn't be so hard. There is, however, a major difference. The SMTP E-mail and Forms Authentication settings are set in the root web.config. Not in applicationhost.config.&lt;/p&gt;  &lt;p&gt;If we open up and compare web.config before, and after we change the setting, we'll notice that the change made by the IIS Manager is adding the following into the root &amp;lt;configuration&amp;gt;-block:&lt;/p&gt;  &lt;div class="DebugSample"&gt;&amp;lt;location path=&amp;quot;&amp;quot; overrideMode=&amp;quot;Deny&amp;quot;&amp;gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;system.net&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;mailSettings&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;smtp&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;network /&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;specifiedPickupDirectory /&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/smtp&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/mailSettings&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/system.net&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;system.web&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;authentication&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;forms&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;credentials /&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/forms&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;passport /&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/authentication&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/system.web&amp;gt;     &lt;br /&gt;&amp;lt;/location&amp;gt; &lt;/div&gt;  &lt;p&gt;Okay, so using what we already know from the &lt;a href="http://blogs.msdn.com/johan/archive/2008/10/02/powershell-advanced-configuration-editing-in-iis7.aspx"&gt;old post&lt;/a&gt; we should put together a call that looks something like this:&lt;/p&gt;  &lt;div class="SampleCode"&gt;Set-WebConfiguration &amp;quot;/System.Net/mailSettings/smtp&amp;quot;&amp;#160; -value @{&amp;lt;something... overrideMode=&amp;quot;Deny&amp;quot;, maybe?&amp;gt;} -PSPath IIS:\&lt;/div&gt;  &lt;p&gt;Please note that this is &lt;strong&gt;NOT&lt;/strong&gt; the correct syntax. It is close, but no cigar. What we need to do is:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Correctly set the overrideMode. The above sample is &lt;em&gt;not &lt;/em&gt;the way to do it. &lt;/li&gt;    &lt;li&gt;Make sure the changes are saved to web.config &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;So, the final, (and correct,) call to the Set-WebConfiguration cmdlet would look like this:&lt;/p&gt;  &lt;div class="SampleCode"&gt;Set-WebConfiguration //System.Net/mailSettings/smtp -metadata overrideMode -value Deny -PSPath MACHINE/WEBROOT&lt;/div&gt;  &lt;p&gt;The Forms Authentication call would look like this:&lt;/p&gt;  &lt;div class="SampleCode"&gt;Set-WebConfiguration //System.Web/authentication -metadata overrideMode -value Deny -PSPath MACHINE/WEBROOT&lt;/div&gt;  &lt;p&gt;I've searched quite extensively for samples on this and so far I've found none. So I thought &lt;em&gt;someone &lt;/em&gt;should write it down. :)&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Happy Holidays! / Johan&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9225881" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/johan/archive/tags/IIS7/default.aspx">IIS7</category><category domain="http://blogs.msdn.com/johan/archive/tags/PowerShell/default.aspx">PowerShell</category></item><item><title>PowerShell - Advanced configuration editing in IIS7</title><link>http://blogs.msdn.com/johan/archive/2008/10/02/powershell-advanced-configuration-editing-in-iis7.aspx</link><pubDate>Thu, 02 Oct 2008 16:28:18 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8973569</guid><dc:creator>JohanS</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/johan/comments/8973569.aspx</comments><wfw:commentRss>http://blogs.msdn.com/johan/commentrss.aspx?PostID=8973569</wfw:commentRss><description>&lt;p&gt;I've written a lot of PowerShell posts lately and here's another one. :-)&lt;/p&gt;  &lt;p&gt;I got a question from one of the account managers if it was possible to alter the FTP Authorization Rules for a specific folder on his IIS.&lt;/p&gt;  &lt;p&gt;&lt;img src="http://blogs.msdn.com/photos/johan/images/8973271/original.aspx" /&gt; &lt;/p&gt;  &lt;p&gt;The appcmd for the operation was&lt;/p&gt;  &lt;p&gt;&lt;span class="InlineCode"&gt;appcmd.exe set config &amp;quot;FTPFolder&amp;quot; -section:system.ftpServer/security/authorization /+&amp;quot;[accessType='Allow',users='*',roles='*',permissions='Read, Write']&amp;quot; /commit:apphost&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span class="InlineCode"&gt;&lt;/span&gt;He wanted to know if there was a PowerShell equivalent. Sure, you could use the appcmd directly from powershell, but if you're going to use the command line for everything, then what's the use of PowerShell?&lt;/p&gt;  &lt;p&gt;The section in applicationhost.config that we want to edit is the following:&lt;/p&gt;  &lt;div class="DebugSample"&gt;&amp;lt;location path=&amp;quot;FTPFolder&amp;quot;&amp;gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;system.ftpServer&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;security&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;authorization&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;add accessType=&amp;quot;Allow&amp;quot; users=&amp;quot;?&amp;quot; permissions=&amp;quot;Read, Write&amp;quot; /&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/authorization&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/security&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/system.ftpServer&amp;gt;     &lt;br /&gt;&amp;lt;/location&amp;gt;&lt;/div&gt;  &lt;h2&gt;&amp;#160;&lt;/h2&gt;  &lt;h2&gt;System Specs&lt;/h2&gt;  &lt;p&gt;As you might have noticed from the screenshots already he was Running Windows 2008 with &lt;a href="http://learn.iis.net/page.aspx/263/installing-and-troubleshooting-ftp7/"&gt;FTP 7&lt;/a&gt; installed. He also had the &lt;a href="http://learn.iis.net/page.aspx/429/installing-the-iis-70-powershell-provider/"&gt;IIS 7.0 PowerShell Provider&lt;/a&gt; installed.&lt;/p&gt;  &lt;h1&gt;Troubleshooting&lt;/h1&gt;  &lt;p&gt;There are a lot of cool things you can do with the WebSites using the IIS7 PowerShell provider. Below is a sample copied from &lt;a href="http://learn.iis.net/page.aspx/436/changing-simple-configuration-settings-in-configuration-sections/"&gt;iis.net&lt;/a&gt;. To use it properly, go to an IIS directory such as IIS:\DemoSite\DemoApp:&lt;/p&gt;  &lt;div class="SampleCode"&gt;$winAuth = Get-WebConfiguration -filter /system.webServer/security/authentication/windowsAuthentication    &lt;br /&gt;$winAuth.enabled = $false     &lt;br /&gt;$winAuth | set-Webconfiguration -filter /system.webServer/security/authentication/windowsAuthentication -PSPath IIS:\ -location &amp;quot;DemoSite/DemoApp&amp;quot;     &lt;br /&gt;&lt;/div&gt;  &lt;p&gt;So judging from the sample above we should simply have to set anonymousAuthentication.enabled = $true or something like that. Unfortunately this isn't the case. If you try to access the section of applicationhost.config that we're attempting to edit (see above) you will see that we don't have any applicable properties for the object. &lt;span class="InlineCode"&gt;$ftpAuth = Get-WebConfiguration -filter /system.ftpServer/security/authorization&lt;/span&gt; will not throw any exceptions, but using TAB to cycle through the properties of $ftpAuth will show us no immediate properties or methods of use. &lt;/p&gt;  &lt;h1&gt;Solution&lt;/h1&gt;  &lt;p&gt;The solution in this scenario is to use the Add-WebConfiguration cmdlet. The applicationhost.config can easily be translated to a valid Add-WebConfiguration call:&lt;/p&gt;  &lt;div class="SampleCode"&gt;Add-WebConfiguration &amp;quot;/system.ftpServer/security/authorization&amp;quot;&amp;#160; -value @{accessType=&amp;quot;Allow&amp;quot;;users=&amp;quot;?&amp;quot;;permissions=3} -PSPath IIS:\ -location FTPFolder&lt;/div&gt;  &lt;p&gt;The only thing that sticks out as being out of the ordinary is the permissions=3 setting. Why isn't it &amp;quot;Read, Write&amp;quot;? Actually, passing &amp;quot;Read, Write&amp;quot; as a parameter will not work. It will leave the permissions setting blank. &amp;quot;Read&amp;quot; or &amp;quot;Write&amp;quot; &lt;em&gt;only&lt;/em&gt; will work, but not both together. I've tried figuring out if there's a valid way of passing both arguments, but so far I've drawn blanks. I've tried putting them in an array {&amp;quot;Read&amp;quot;;&amp;quot;Write&amp;quot;}, passing them as &amp;quot;ReadWrite&amp;quot;, &amp;quot;Read;Write&amp;quot;, &amp;quot;Read+Write&amp;quot; etc. but the only way I've found so far is to pass the value 3 which is the obvious sum of the two enum values for Read and Write.&lt;/p&gt;  &lt;p&gt;Later! / Johan&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8973569" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/johan/archive/tags/IIS7/default.aspx">IIS7</category><category domain="http://blogs.msdn.com/johan/archive/tags/PowerShell/default.aspx">PowerShell</category></item><item><title>PowerShell - Editing permissions on a file or folder</title><link>http://blogs.msdn.com/johan/archive/2008/10/01/powershell-editing-permissions-on-a-file-or-folder.aspx</link><pubDate>Wed, 01 Oct 2008 15:52:49 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8971522</guid><dc:creator>JohanS</dc:creator><slash:comments>7</slash:comments><comments>http://blogs.msdn.com/johan/comments/8971522.aspx</comments><wfw:commentRss>http://blogs.msdn.com/johan/commentrss.aspx?PostID=8971522</wfw:commentRss><description>&lt;p&gt;I got the following question from a reader the other day:&lt;/p&gt;  &lt;p&gt;&lt;em&gt;I've been trying to figure out how to change permissions on a folder in PowerShell. I've looked at the Get-Acl and Set-Acl, but I can only use them to copy the settings from a pre-existing object. How do I manually configure permissions?&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;This is actually a quite common question, so I thought I'd write a quick post on the subject.&lt;/p&gt;  &lt;h1&gt;Get-Acl and Set-Acl&lt;/h1&gt;  &lt;p&gt;To quote the PowerShell documentation &amp;quot;Get-Acl &lt;em&gt;gets&lt;/em&gt; the security descriptor for a resource, such as a file or registry key.&amp;quot; while &amp;quot;Set-Acl &lt;em&gt;changes&lt;/em&gt; the security descriptor of a specified resource, such as a file or a registry key.&amp;quot; In other words; if you want Folder_A to have the exact same permissions as Folder_B, then you simply copy the Access Control List (ACL) of Folder_B and &amp;quot;paste&amp;quot; it onto Folder_A.&lt;/p&gt;  &lt;div class="SampleCode"&gt;   &lt;pre&gt;$Acl = Get-Acl &amp;quot;C:\Folder_B&amp;quot;
Set-Acl &amp;quot;C:\Folder_A&amp;quot; $Acl&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;So far, so good.&lt;/p&gt;

&lt;h1&gt;Changing the ACL&lt;/h1&gt;

&lt;p&gt;Okay, so you want to change the ACL. Here's some sample code for how to do that:&lt;/p&gt;

&lt;div class="SampleCode"&gt;
  &lt;pre&gt;New-Item -type directory -path C:\MyFolder
$Acl = Get-Acl &amp;quot;C:\MyFolder&amp;quot;
$Ar = New-Object  system.security.accesscontrol.filesystemaccessrule(&amp;quot;username&amp;quot;,&amp;quot;FullControl&amp;quot;,&amp;quot;Allow&amp;quot;)
$Acl.SetAccessRule($Ar)
Set-Acl &amp;quot;C:\MyFolder&amp;quot; $Acl&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;So, first we create a new folder. We then copy the ACL of that folder. We then create a new AccessRule that gives &amp;quot;username&amp;quot; full control. We then add this AccessRule to the ACL, and finally we reapply the new, altered ACL to the folder.&lt;/p&gt;

&lt;p&gt;If we wanted to we could also have used &lt;span class="InlineCode"&gt;$Acl.RemoveAccessRule($Ar)&lt;/span&gt; or possibly &lt;span class="InlineCode"&gt;$Acl.RemoveAccessRuleAll()&lt;/span&gt; as well.&lt;/p&gt;

&lt;p&gt;/ Johan&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8971522" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/johan/archive/tags/Script/default.aspx">Script</category><category domain="http://blogs.msdn.com/johan/archive/tags/Sample+Code/default.aspx">Sample Code</category><category domain="http://blogs.msdn.com/johan/archive/tags/PowerShell/default.aspx">PowerShell</category></item><item><title>PowerShell - Automatically organizing your mp3-collection</title><link>http://blogs.msdn.com/johan/archive/2008/09/23/powershell-automatically-organizing-your-mp3-collection.aspx</link><pubDate>Tue, 23 Sep 2008 14:53:23 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8962147</guid><dc:creator>JohanS</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/johan/comments/8962147.aspx</comments><wfw:commentRss>http://blogs.msdn.com/johan/commentrss.aspx?PostID=8962147</wfw:commentRss><description>&lt;p&gt;Is your mp3-collection perfectly sorted? I know mine wasn't. I thought I'd address that while creating a pretty good demo-script to show some basic filtering, script structures, etc. Since I also wanted the script to extract the metadata from every file in my collection I had to use the Shell.Application Com-object as well. All in all I think it turned out pretty well.&lt;/p&gt;  &lt;p&gt;NOTE:&lt;/p&gt;  &lt;p&gt;This script is provided completely as is. It is not an official product in any way and I take no responsibility for any harm it may cause.&lt;/p&gt;  &lt;p&gt;Please note that certain metadata editors that integrate directly into the Shell may cause some severe confusion in the metadata, so I'd recommend disabling them before trying. Off course I would also recommend making a backup copy of the music library before surrendering it to the mercy of PowerShell.&lt;/p&gt;  &lt;p&gt;If you're new to PowerShell and haven't done so already I'd recommend looking at my earlier posts on the subject:    &lt;br /&gt;&lt;a href="http://blogs.msdn.com/johan/archive/2008/05/28/powershell-an-introduction-part-i.aspx"&gt;PowerShell - An introduction, Part I&lt;/a&gt;     &lt;br /&gt;&lt;a href="http://blogs.msdn.com/johan/archive/2008/08/25/powershell-an-introduction-part-ii.aspx"&gt;PowerShell - An introduction, Part II&lt;/a&gt;&lt;/p&gt;  &lt;h1&gt;The script    &lt;br /&gt;&lt;/h1&gt;  &lt;div class="SampleCode"&gt;   &lt;pre&gt;Param([String] $Folder)
$INVALIDCHARS = [System.IO.Path]::GetInvalidPathChars() + &amp;quot;/&amp;quot;, &amp;quot;\&amp;quot;, &amp;quot;*&amp;quot;, &amp;quot;?&amp;quot;, &amp;quot;:&amp;quot;
$MUSICATTRIBS = &amp;quot;*.m4a&amp;quot;, &amp;quot;*.m4b&amp;quot;, &amp;quot;*.mp3&amp;quot;, &amp;quot;*.mp4&amp;quot;, &amp;quot;*.wma&amp;quot;, &amp;quot;*.flc&amp;quot;
$PLAYLISTATTRIBS = &amp;quot;*.m3u&amp;quot;, &amp;quot;*.zpl&amp;quot;
$ALLATTRIBS = $MUSICATTRIBS + $PLAYLISTATTRIBS&lt;br /&gt;$PLAYLISTSFOLDER = &amp;quot;Playlists&amp;quot;
$objShell = New-Object -ComObject Shell.Application
$iTotalFiles = 0
$iCurrentFile = 0

function checkFolderName($FolderName)
{
	&lt;font color="#00ff00"&gt;&lt;font color="#008000"&gt;# Make sure the folder doesn't contain any invalid characters&lt;/font&gt;
&lt;/font&gt;
	if(!$FolderName) { $FolderName = &amp;quot;Unknown&amp;quot; }
	$INVALIDCHARS | % {$FolderName = $FolderName.replace($_, &amp;quot;&amp;quot;)}
	return $FolderName
}



function MoveFiles($startDir)
{
	Write-Host &amp;quot;Indexing playlists...&amp;quot;
	
	&lt;font color="#008000"&gt;# Do a recursive DIR in the starting directory, include everything with the attributes of a playlist.
	# Filter the result by excluding everything that is a Container (folder)
&lt;/font&gt;	$dirResult = get-childitem -force -path $startDir -recurse -include $PLAYLISTATTRIBS | where{! $_.PSIsContainer}
	if($dirResult)
	{
		Write-Host &amp;quot;Moving playlists...&amp;quot;

		foreach($dirItem in $dirResult)
		{
			move-item $dirItem.FullName ($PLAYLISTSFOLDER + &amp;quot;\&amp;quot; + $dirItem.Name)
		}
	}
	Write-Host &amp;quot;Indexing music...&amp;quot;

&lt;font color="#008000"&gt;	# Do a recursive DIR in the starting directory, include everything with the attributes of a music file.
	# Again we filter the result by excluding everything that is a Container.
&lt;/font&gt;	$dirResult = get-childitem -force -path $startDir -recurse -include $MUSICATTRIBS | where{! $_.PSIsContainer}
	
&lt;font color="#008000"&gt;	# Make a note of how many hits we got, so we can show the progress to the client.
&lt;/font&gt;	$iTotalFiles = $dirResult.Count
	if($dirResult)
	{
		foreach($dirItem in $dirResult)
		{
&lt;font color="#008000"&gt;			# Up the counter for how many files we've processed so that we can show progress
&lt;/font&gt;			$iCurrentFile +=1

&lt;font color="#008000"&gt;			# Get the metadata for the file
&lt;/font&gt;			$fileData = getMP3MetaData($dirItem.FullName)
			
&lt;font color="#008000"&gt;			# Find the path where we the song should be stored
&lt;/font&gt;			$ArtistPath = $fileData[&amp;quot;Album Artist&amp;quot;]
			if (!$ArtistPath) { $ArtistPath = $fileData[&amp;quot;Artists&amp;quot;] }
			if (!$ArtistPath) { $ArtistName = &amp;quot;Unknown&amp;quot; }

&lt;font color="#008000"&gt;			# Make shure it's a valid path
&lt;/font&gt;			$ArtistPath = checkFolderName($ArtistPath)
			$AlbumPath = checkFolderName($fileData.Album)
			$ArtistPath = join-path $startDir $ArtistPath 
			$AlbumPath = join-path $ArtistPath $AlbumPath

&lt;font color="#008000"&gt;			# Check if the file should be moved
&lt;/font&gt;			if($dirItem.DirectoryName -ne $AlbumPath)
			{
				if(!(test-path $ArtistPath)) &lt;font color="#008000"&gt;# If the Artist folder doesn't exist
&lt;/font&gt;				{
					MKDIR $ArtistPath | out-null
				}
				if(!(test-path $AlbumPath)) &lt;font color="#008000"&gt;# If the Album folder doesn't exist&lt;/font&gt;
				{
					MKDIR $AlbumPath | out-null
				}
				move-item $dirItem.FullName ($AlbumPath + &amp;quot;\&amp;quot; + $dirItem.Name)
			}

&lt;font color="#008000"&gt;			# Show progress
&lt;/font&gt;			$percentage = ([int](($iCurrentFile / $iTotalFiles)*100))
			cls
			Write-Host &amp;quot;$percentage% ($iCurrentFile files of $iTotalFiles) complete&amp;quot;
		}
	}
}


function removeEmptyFolders($startDir)
{
&lt;font color="#008000"&gt;	# Get all folders and subfolders
&lt;/font&gt;	$dirResult = Get-childitem $startDir -recurse | where{$_.PSIsContainer}
	if($dirResult)
	{
		foreach($dirItem in $dirResult)
		{
&lt;font color="#008000"&gt;			# If the folder is empty (Doesn't contain any music or playlists) it should be deleted
&lt;/font&gt;			if(isfolderempty($dirItem.FullName))
			{
&lt;font color="#008000"&gt;				# Check if the path is still valid, we may have deleted the folder already recursively.
&lt;/font&gt;				if(Test-Path $dirItem.FullName)
				{
					remove-item -path $dirItem.FullName -force -recurse
				}
			}
		}
	}
}

function removeOtherFiles($startDir)
{
&lt;font color="#008000"&gt;	# Get all non-music files (except *.jpg-files) and remove them 
&lt;/font&gt;	$dirResult = Get-childitem $startDir -recurse -exclude ($ALLATTRIBS + &amp;quot;*.jpg&amp;quot;) | where{! $_.PSIsContainer}
	if($dirResult)
	{
		foreach($dirItem in $dirResult)
		{
			if(Test-Path $dirItem.FullName)
			{
&lt;font color="#008000"&gt;				# Make sure the file still exists, and hasn't been deleted already
&lt;/font&gt;				remove-item -path $dirItem.FullName -force
			}
		}
	}
}

function isFolderEmpty($folderPath)
{
&lt;font color="#008000"&gt;	# Search for any remaining music items in the folder.&lt;/font&gt;
	if(Test-Path $folderPath)
	{
		$dirChildren = get-childitem -force -path $folderPath -recurse -include $ALLATTRIBS | where{! $_.PSIsContainer}
		if($dirChildren -ne $null)
		{
			return $false
		}
		else
		{
			return $true
		}
	}
	else
	{
&lt;font color="#008000"&gt;		# No use trying to delete the folder if it doesn't exist
&lt;/font&gt;		return $false
	}
}

function getMP3MetaData($path)
{
&lt;font color="#008000"&gt;	# Get the file name, and the folder it exists in
&lt;/font&gt;	$file = split-path $path -leaf
	$path = split-path $path
	$objFolder = $objShell.namespace($path)
	$objFile = $objFolder.parsename($file)
	$result = @{}
	0..266 | % {
		if ($objFolder.getDetailsOf($objFile, $_))
		{
			$result[$($objFolder.getDetailsOf($objFolder.items, $_))] = $objFolder.getDetailsOf($objFile, $_)
		}
	}
	return $result
}

&lt;font color="#008000"&gt;# MAIN FUNCTION&lt;/font&gt;

&lt;font color="#008000"&gt;# If no argument was passed, see if anything was piped to the function instead.&lt;/font&gt;
if (!$Folder)
{
	$input | % { $Folder = $_ }
}

&lt;font color="#008000"&gt;# Check if the path is valid, if not reset it to &amp;quot;&amp;quot;&lt;/font&gt;
if ($Folder) { if (!(Test-Path -path $Folder)) { $Folder = &amp;quot;&amp;quot; }}

&lt;font color="#008000"&gt;# Since no valid path was given, prompt the user for a proper path.&lt;/font&gt;
while (!$Folder)
{
	&amp;quot;Please enter the full path to the folder where you wish to rearrange your MP3's&amp;quot;
	$Folder = Read-Host
	if ($Folder) { if (!(Test-Path -path $Folder)) { $Folder = &amp;quot;&amp;quot; }}
}

&lt;font color="#008000"&gt;# Make sure we have a folder to store the playlists in.&lt;/font&gt;
$PLAYLISTSFOLDER = join-path $Folder $PLAYLISTSFOLDER
if(!(test-path $PLAYLISTSFOLDER)) # If the Playlists folder doesn't exist
{
	MKDIR $PLAYLISTSFOLDER | out-null
}

&lt;font color="#008000"&gt;# Now that everything is ready, begin rearranging the files.&lt;/font&gt;
MoveFiles($Folder)
removeEmptyFolders($Folder)
removeOtherFiles($Folder)&lt;/pre&gt;
&lt;/div&gt;

&lt;h1&gt;&amp;#160;&lt;/h1&gt;

&lt;h1&gt;&lt;/h1&gt;

&lt;h1&gt;Running the script&lt;/h1&gt;

&lt;p&gt;So, how do you run this script?&lt;/p&gt;

&lt;p&gt;It's quite easy. The first step would be to copy it into notepad save it with a .ps1 extension and open up PowerShell&lt;/p&gt;

&lt;h2&gt;Execution policy&lt;/h2&gt;

&lt;p&gt;If this is the first time you try to execute a script from PowerShell you will most likely have to change the execution policy for PowerShell. I'd recommend setting it to RemoteSigned. This (obviously) means that all remote scripts must be signed or PowerShell will refuse to execute them. To change the execution policy simply type:&lt;/p&gt;

&lt;div class="SampleCode"&gt;Set-ExecutionPolicy RemoteSigned&lt;/div&gt;

&lt;p&gt;That's it.&lt;/p&gt;

&lt;p&gt;If you're uncertain what your execution policy setting is you simply type:&lt;/p&gt;

&lt;div class="SampleCode"&gt;Get-ExecutionPolicy&lt;/div&gt;

&lt;p&gt;Okay, having changed that we can now execute the script. If you saved the script in a folder that is in your system path you only need to type the filename of the .ps1 file. (The .ps1 is optional) So, if you saved it as RearrangeMP3s.ps1 you'd write &lt;span class="InlineCode"&gt;RearrangeMP3s&lt;/span&gt; and press enter &lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;h1&gt;Breakdown&lt;/h1&gt;

&lt;p&gt;Okay, so let's take a look at the separate parts of the script.&lt;/p&gt;

&lt;h2&gt;Initial variables and constants&lt;/h2&gt;

&lt;p&gt;First we declare the parameters we're going to use. In this case it's just one: $Folder.&lt;/p&gt;

&lt;p&gt;After that we have some constants. You may want to change $MUSICATTRIBS or $PLAYLISTATTRIBS to include, or remove, extensions based on your needs. $PLAYLISTSFOLDER is a constant which indicates in which subfolder you wish to store your playlists.&lt;/p&gt;

&lt;p&gt;Finally we have some variables. $objShell is used for file system operations, and rather than creating a new object all the time I'd rather have a global one. $iTotalFiles and $iCurrentFile are two integers used to create a progress indicator.&lt;/p&gt;

&lt;h2&gt;Functions&lt;/h2&gt;

&lt;p&gt;After the initial variables come the sub functions called by the main function. To see what each individual function does I'd recommend looking at the comments. I've prioritized readability over minimum number of keystrokes, so yes, instead of writing:&lt;/p&gt;

&lt;div class="SampleCode"&gt;
  &lt;pre&gt;foreach($dirItem in $dirResult)
{
	move-item $dirItem.FullName ($PLAYLISTSFOLDER + &amp;quot;\&amp;quot; + $dirItem.Name)
}&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;I could have written&lt;/p&gt;

&lt;div class="SampleCode"&gt;
  &lt;pre&gt;$dirResult | % { mv $_.FullName ($PLAYLISTSFOLDER + &amp;quot;\&amp;quot; + $_.Name) }&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;But in this case I think that would have been counterproductive.&lt;/p&gt;

&lt;h2&gt;The main function&lt;/h2&gt;

&lt;p&gt;Finally we have the main function. It is written last in the script. Why is that? Well, actually PowerShell is the most sequential language you'll ever come across. It will not bother to check the entire script for function declarations. Instead it will go through the script one line at a time. This means that the following script will not work:&lt;/p&gt;

&lt;div class="SampleCode"&gt;
  &lt;pre&gt;SayHello

function SayHello
{
	Write-Host &amp;quot;Hello World&amp;quot;
}&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;When you call SayHello in the sample above the function has not yet been declared, so PowerShell will throw an exception in your face saying that SayHello is unrecognized.&lt;/p&gt;

&lt;h1&gt;&lt;/h1&gt;

&lt;h1&gt;Footnote&lt;/h1&gt;

&lt;p&gt;There is actually a &lt;em&gt;supported&lt;/em&gt; way of achieving the very same thing, but where's the fun in that?&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Open up Windows Media Player&lt;/li&gt;

  &lt;li&gt;Go to Options -&amp;gt; Library and tick the checkbox for &amp;quot;Rearrange music in rip folder&amp;quot;&lt;/li&gt;

  &lt;li&gt;Go to the &amp;quot;Rip Music&amp;quot;-tab&lt;/li&gt;

  &lt;li&gt;Make sure the path is correct in the &amp;quot;Rip music to this location&amp;quot;-section&lt;/li&gt;

  &lt;li&gt;Click OK&lt;/li&gt;

  &lt;li&gt;Select &lt;em&gt;all&lt;/em&gt; files in the library&lt;/li&gt;

  &lt;li&gt;Right-click and choose the &amp;quot;Advanced Tag Editor&amp;quot;-option&lt;/li&gt;

  &lt;li&gt;Do not change anything. Simply click Apply&lt;/li&gt;

  &lt;li&gt;Windows Media Player will now rearrange all the files using your Rip settings.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;/ Johan&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8962147" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/johan/archive/tags/Script/default.aspx">Script</category><category domain="http://blogs.msdn.com/johan/archive/tags/Sample+Code/default.aspx">Sample Code</category><category domain="http://blogs.msdn.com/johan/archive/tags/PowerShell/default.aspx">PowerShell</category></item><item><title>PowerShell - An introduction, Part II</title><link>http://blogs.msdn.com/johan/archive/2008/08/25/powershell-an-introduction-part-ii.aspx</link><pubDate>Mon, 25 Aug 2008 14:22:12 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8893706</guid><dc:creator>JohanS</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/johan/comments/8893706.aspx</comments><wfw:commentRss>http://blogs.msdn.com/johan/commentrss.aspx?PostID=8893706</wfw:commentRss><description>&lt;p&gt;This is a continuation of &lt;a href="http://blogs.msdn.com/johan/archive/2008/05/28/powershell-an-introduction-part-i.aspx"&gt;part I&lt;/a&gt;. If you haven't read it I suggest at least going through the summary at the end of the post.&lt;/p&gt;  &lt;h1&gt;Working with Drives&lt;/h1&gt;  &lt;p&gt;In your basic command prompt you have the normal file system drives that you use to access your hard-drive, floppy, DVD, USB-stick, network shares etc. PowerShell uses this established interface to access other data sources as well. The following providers are accessible by default through drives in PowerShell 1.0:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Registry (HKLM: or HKCU:) &lt;/li&gt;    &lt;li&gt;Certificate store (Cert:) &lt;/li&gt;    &lt;li&gt;Environment variables (Env:) &lt;/li&gt;    &lt;li&gt;Aliases (Alias:) &lt;/li&gt;    &lt;li&gt;Functions (Function:) &lt;/li&gt;    &lt;li&gt;Variables (Variable:) &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;When you install extensions for like the one fore IIS, etc. you usually get another drive accessible where you can look at the current webapplications and check their properties.&lt;/p&gt;  &lt;h2&gt;Navigating&lt;/h2&gt;  &lt;p&gt;Selecting one of the PowerShell drives is easy. It is &lt;em&gt;almost&lt;/em&gt; like in MS-DOS.&lt;/p&gt;  &lt;div class="SampleCode"&gt;PS C:\&amp;gt;CD HKLM:    &lt;br /&gt;PS HKLM:\&amp;gt; DIR&lt;/div&gt;  &lt;p&gt;You can use the same commands as you'd do in MS-DOS, such as CD, DIR, MKDIR, etc.&lt;/p&gt;  &lt;p&gt;To get a certain property for a registry key, (or a regular folder for that matter) you use the Get-ItemProperty cmdlet.&lt;/p&gt;  &lt;div class="SampleCode"&gt;PS HKLM:\&amp;gt; CD system    &lt;br /&gt;PS HKLM:\system&amp;gt; CD CurrentControlSet\Control     &lt;br /&gt;PS HKLM:\system\CurrentControlSet\Control&amp;gt; Get-ItemProperty CrashControl     &lt;br /&gt;&amp;#160; &lt;br /&gt;PSPath&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\system\CurrentControlSet\Control\CrashControl     &lt;br /&gt;PSParentPath&amp;#160;&amp;#160;&amp;#160;&amp;#160; : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\system\CurrentControlSet\Control     &lt;br /&gt;PSChildName&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; : CrashControl     &lt;br /&gt;PSDrive&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; : HKLM     &lt;br /&gt;PSProvider&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; : Microsoft.PowerShell.Core\Registry     &lt;br /&gt;AutoReboot&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; : 1     &lt;br /&gt;CrashDumpEnabled : 2     &lt;br /&gt;Overwrite&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; : 1     &lt;br /&gt;LogEvent&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; : 1     &lt;br /&gt;DumpFile&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; : C:\Windows\MEMORY.DMP     &lt;br /&gt;MinidumpDir&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; : C:\Windows\Minidump&lt;/div&gt;  &lt;p&gt;All in all it's more or less the same working with Aliases or Environment variables. Note the following difference in output, though:&lt;/p&gt;  &lt;div class="SampleCode"&gt;PS Env:\&amp;gt; Dir Env:PROCESSOR_ARCHITECTURE    &lt;br /&gt;&amp;#160; &lt;br /&gt;Name&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Value     &lt;br /&gt;----&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; -----     &lt;br /&gt;PROCESSOR_ARCHITECTURE&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; AMD64     &lt;br /&gt;&amp;#160; &lt;br /&gt;PS Env:\&amp;gt; $Env:PROCESSOR_ARCHITECTURE     &lt;br /&gt;AMD64     &lt;br /&gt;PS Env:\&amp;gt;&lt;/div&gt;  &lt;p&gt;Did you note how putting a $-sign before the variable name gave us the value of the variable instead of a complete object? This brings us quite nicely to the subject of variables.&lt;/p&gt;  &lt;h1&gt;Variables&lt;/h1&gt;  &lt;p&gt;Variables aren't that tricky to work with. They do not need to be pre-initiated. They do, however, require a $ to be identified as variables. Otherwise you get the following error message:&lt;/p&gt;  &lt;div class="SampleCode"&gt;PS C:\&amp;gt; $Name = &amp;quot;Johan&amp;quot;    &lt;br /&gt;PS C:\&amp;gt; Name = &amp;quot;Johan&amp;quot;     &lt;br /&gt;&lt;font color="#ff0000"&gt;The term 'Name' is not recognized as a cmdlet, function, operable program, or script file. Verify the term and try again.      &lt;br /&gt;At line:1 char:5       &lt;br /&gt;+ Name&amp;#160; &amp;lt;&amp;lt;&amp;lt;&amp;lt; = &amp;quot;Johan&amp;quot;&lt;/font&gt;     &lt;br /&gt;PS C:\&amp;gt;&lt;/div&gt;  &lt;p&gt;To display the value of a variable you simply type the name of the variable and PowerShell kindly returns the contents&lt;/p&gt;  &lt;div class="SampleCode"&gt;PS C:\&amp;gt; $Name    &lt;br /&gt;Johan&lt;/div&gt;  &lt;p&gt;When it comes to strings, you can choose for yourself if you want to use double quotes or single quotes, but there is one minor difference: &lt;/p&gt;  &lt;div class="SampleCode"&gt;PS C:\&amp;gt; $str1 = &amp;quot;Hello&amp;quot;    &lt;br /&gt;PS C:\&amp;gt; $str2 = &amp;quot;World!&amp;quot;     &lt;br /&gt;PS C:\&amp;gt; $strCombo1 = &amp;quot;$str1 $str2&amp;quot;     &lt;br /&gt;PS C:\&amp;gt; $strCombo2 = '$str1 $str2'     &lt;br /&gt;PS C:\&amp;gt; $strCombo1     &lt;br /&gt;Hello World!     &lt;br /&gt;PS C:\&amp;gt; $strCombo2     &lt;br /&gt;$str1 $str2     &lt;br /&gt;PS C:\&amp;gt; &lt;/div&gt;  &lt;p&gt;As you can see, a variable within double quotes will be evaluated, while within single quotes it will be interpreted literally.&lt;/p&gt;  &lt;p&gt;Apart from strings you can also store integers and dates. Integers do not need delimiters and dates are most easily created using the Get-Date function&lt;/p&gt;  &lt;div class="SampleCode"&gt;PS C:\&amp;gt; $birthday = 11/15/1973&lt;/div&gt;  &lt;h1&gt;&amp;#160;&lt;/h1&gt;  &lt;h1&gt;Arrays&lt;/h1&gt;  &lt;p&gt;Declaring Arrays is a breeze. PowerShell will automatically &lt;em&gt;Split&lt;/em&gt; any comma-separated sequence of values so creating a arrays is as easy as this:&lt;/p&gt;  &lt;div class="SampleCode"&gt;PS C:\&amp;gt; $Colors = &amp;quot;Red&amp;quot;, &amp;quot;Green&amp;quot;, &amp;quot;Blue&amp;quot;&lt;/div&gt;  &lt;p&gt;The arrays are also dynamic by default, so adding values to them is a simple matter as well.&lt;/p&gt;  &lt;div class="SampleCode"&gt;PS C:\&amp;gt; $Colors += &amp;quot;Cyan&amp;quot;, &amp;quot;Magenta&amp;quot;, &amp;quot;Yellow&amp;quot;&lt;/div&gt;  &lt;p&gt;Creating two-dimensional arrays are done by declaring each row of the array as a one-dimensional array and then adding them to &lt;em&gt;another&lt;/em&gt; array:&lt;/p&gt;  &lt;div class="SampleCode"&gt;PS C:\&amp;gt; $arr1 = 1, 2, 3    &lt;br /&gt;PS C:\&amp;gt; $arr2 = &amp;quot;A&amp;quot;, &amp;quot;B&amp;quot;, &amp;quot;C&amp;quot;     &lt;br /&gt;PS C:\&amp;gt; $arr3 = $arr1, $arr2     &lt;br /&gt;PS C:\&amp;gt; $arr3[0][0]     &lt;br /&gt;1     &lt;br /&gt;PS C:\&amp;gt; $arr3[1][1]     &lt;br /&gt;B     &lt;br /&gt;PS C:\&amp;gt;&lt;/div&gt;  &lt;h1&gt;&amp;#160;&lt;/h1&gt;  &lt;h1&gt;User input &lt;/h1&gt;  &lt;p&gt;Finally, to get dynamic user input you can use the Read-Host cmdlet.&lt;/p&gt;  &lt;div class="SampleCode"&gt;$Name = Read-Host &amp;quot;What is your name?&amp;quot;&lt;/div&gt;  &lt;h1&gt;&amp;#160;&lt;/h1&gt;  &lt;h1&gt;Summary&lt;/h1&gt;  &lt;p&gt;Okay, so to summarize we have now covered the following:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;PowerShell uses system drives to access the registry, environment variables, etc.&lt;/li&gt;    &lt;li&gt;Variables are preceded with a $&lt;/li&gt;    &lt;li&gt;To access the value of a variable, simply type it's name.&lt;/li&gt;    &lt;li&gt;Arrays are comma-separated lists of variables&lt;/li&gt;    &lt;li&gt;User input can be handled by the Read-Host cmdlet&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Next post will probably cover some script logic such as if-clauses, looping, etc. After that I think it will be time to post some sample scripts.&lt;/p&gt;  &lt;p&gt;/ Johan&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8893706" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/johan/archive/tags/PowerShell/default.aspx">PowerShell</category></item><item><title>PowerShell – An introduction, Part I</title><link>http://blogs.msdn.com/johan/archive/2008/05/28/powershell-an-introduction-part-i.aspx</link><pubDate>Wed, 28 May 2008 14:53:15 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8556478</guid><dc:creator>JohanS</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/johan/comments/8556478.aspx</comments><wfw:commentRss>http://blogs.msdn.com/johan/commentrss.aspx?PostID=8556478</wfw:commentRss><description>&lt;p&gt;&lt;/p&gt; &lt;p&gt;Over the past months I’ve been holding a couple of workshops on PowerShell. It’s quite an interesting topic, but not something I originally thought would be suitable for this blog and its web-development theme. Still, having given this a bit more thought I decided that there are so many useful features and cmdlets that could be of great value when hosting a web site or two that I should reconsider.&lt;/p&gt; &lt;p&gt;This first post will be a brief introduction for those who’ve never touched PowerShell before. Later posts will probably be more hands-on and less theoretical. I’ll gladly receive any thoughts or comments you may have.&lt;/p&gt; &lt;h1&gt;Installing&lt;/h1&gt; &lt;p&gt;PowerShell can be downloaded from the Microsoft web site. Simply point your browser to &lt;a href="http://www.microsoft.com/powershell"&gt;http://www.microsoft.com/powershell&lt;/a&gt; and you’ll be set in no time. Apart from the executables you’ll find a lot of useful links, like the one to the &lt;a href="http://blogs.msdn.com/PowerShell/"&gt;PowerShell team blog&lt;/a&gt; and the &lt;a href="http://learn.iis.net/Themes/IIS/Pages/search.aspx?q=powershell"&gt;IIS 7.0 PowerShell Provider&lt;/a&gt;.&lt;/p&gt; &lt;h1&gt;Basic syntax&lt;/h1&gt; &lt;p&gt;Okay, having installed PowerShell we’re now ready to try some basic commands.&lt;/p&gt; &lt;h2&gt;Echoing text&lt;/h2&gt; &lt;p&gt;Any object not used in an assignment or operation will be echoed to the screen. This means that if we simply type a string like this:&lt;/p&gt; &lt;div class="SampleCode"&gt;PS C:\&amp;gt;“Hello World”&lt;br&gt;Hello World&lt;/div&gt; &lt;p&gt;It will be displayed on the screen. (Without the quotes.) The same goes for numbers, so by typing an equation you’ll be given the result:&lt;/p&gt; &lt;div class="SampleCode"&gt;PS C:\&amp;gt;1 + 1&lt;br&gt;2&lt;/div&gt; &lt;p&gt;If you type in an array PowerShell will echo it one line at a time:&lt;/p&gt; &lt;div class="SampleCode"&gt;PS C:\&amp;gt;“foo”, “bar”, “bletch”, “fum”&lt;br&gt;foo&lt;br&gt;bar&lt;br&gt;bletch&lt;br&gt;fum&lt;/div&gt; &lt;p&gt;Basically you could say that any object will, unless told otherwise, be displayed on screen using its default formatting. The default formatting is defined by the object itself.&lt;/p&gt; &lt;h2&gt;Calling executables&lt;/h2&gt; &lt;p&gt;Running an executable is more or less as easy as in the regular command shell. At least if the .exe is in the PATH. For any executable &lt;em&gt;not&lt;/em&gt; in the PATH you'll need to write the full path of the .exe for it to successfully execute. This may seem like a hassle, but this behavior is by design and was implemented in order to prevent you from accidentally executing an .exe.&lt;/p&gt; &lt;h1&gt;Cmdlets&lt;/h1&gt; &lt;p&gt;Cmdlets (pronounced "command-lets") are PowerShell-specific commands. They follow a strict naming standard of &lt;em&gt;verb-noun&lt;/em&gt;, (for example "get-date" or "set-location").&lt;/p&gt; &lt;h2&gt;Get-Help&lt;/h2&gt; &lt;p&gt;This a command that you'll use quite a lot. &lt;span class="InlineCode"&gt;Get-Help &amp;lt;cmdlet&amp;gt;&lt;/span&gt; will display some generic information about the cmdlet in question. Using various switches such as "-detailed", "-examples" or "-full" you can then get more detailed information on the cmdlet in question. For example:&lt;/p&gt; &lt;div class="SampleCode"&gt;Get-Help Get-Date -examples&lt;/div&gt; &lt;p&gt;This will show you the generic information on get-date as well as some sample code.&lt;/p&gt; &lt;h2&gt;Set-Location&lt;/h2&gt; &lt;p&gt;Set-Location is the PowerShell equivalent to the old MS-DOS command "CD". Some examples are:&lt;/p&gt; &lt;div class="SampleCode"&gt;Set-Location ..&lt;br&gt;Set-Location C:\Windows\&lt;br&gt;Set-Location D:&lt;/div&gt; &lt;h2&gt;&lt;/h2&gt; &lt;h2&gt;&amp;nbsp;&lt;/h2&gt; &lt;h2&gt;Aliases&lt;/h2&gt; &lt;p&gt;Actually you can write CD in PowerShell too. By default PowerShell will set up an alias for you that points to the Set-Location cmdlet. This means that CD is just another name for Set-Location. If you want you can create your own aliases using the New-Alias cmdlet:&lt;/p&gt; &lt;div class="SampleCode"&gt;New-Alias gh Get-Help&lt;/div&gt; &lt;p&gt;This creates an alias named gh that points at Get-Help. If you type &lt;span class="InlineCode"&gt;Get-Help gh&lt;/span&gt; PowerShell will be smart enough to show you the documentation for the Get-Help cmdlet.&lt;/p&gt; &lt;h1&gt;Object orientation&lt;/h1&gt; &lt;p&gt;One of the cool things about PowerShell is that it is object oriented. This means that all the cmdlets return objects, which can, in turn, be passed on to another cmdlet. To illustrate this, let’s look at the DIR-command.&lt;/p&gt; &lt;h2&gt;Using DIR&lt;/h2&gt; &lt;p&gt;You can use DIR in PowerShell, but it is actually an alias for the get-childitem cmdlet. How can you tell? Use the get-command cmdlet:&lt;/p&gt; &lt;div class="SampleCode"&gt;PS C:\&amp;gt; get-command dir&lt;br&gt;&amp;nbsp;&lt;br&gt;CommandType&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Name&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Definition&lt;br&gt;-----------&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ----&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ----------&lt;br&gt;Alias&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dir&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Get-ChildItem&lt;/div&gt; &lt;p&gt;Since DIR in PowerShell is not the same thing as DIR in MS-DOS that means you can’t use all the switches you might be used to, for example DIR /w will not work.&lt;/p&gt; &lt;p&gt;So, what happens when you type DIR and press enter?&lt;/p&gt; &lt;p&gt;Well, first of all the get-childitem cmdlet is run. It looks in your present working directory, creates a collection of all the items there, and returns it. You can think of this collection as a big Excel Spreadsheet if you like.&lt;/p&gt; &lt;p&gt;Once the collection is returned to PowerShell it will be displayed on screen. This is because the default behavior for PowerShell when it comes to &lt;em&gt;any&lt;/em&gt; object is to display it on screen. We saw this earlier with strings, integers and arrays.&lt;/p&gt; &lt;p&gt;The collection will be displayed using a default presentation. This does not mean you will see all the information the object contains. If I run Get-ChildItem (DIR) on a folder I’ll get the standard information. Like so:&lt;/p&gt; &lt;div class="SampleCode"&gt;PS C:\Test&amp;gt; dir &lt;br&gt;&amp;nbsp;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Directory: Microsoft.PowerShell.Core\FileSystem::C:\Test &lt;br&gt;&amp;nbsp;&lt;br&gt;Mode&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LastWriteTime&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Length Name&lt;br&gt;----&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; -------------&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ------ ----&lt;br&gt;-a---&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2008-05-28&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 11:25&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 45568 Document.doc&lt;br&gt;-a---&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2008-05-26&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 10:00&amp;nbsp;&amp;nbsp;&amp;nbsp; 8993629 Satisfaction.mp3&lt;br&gt;-a---&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2008-05-28&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 11:25&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1599 Text.txt&lt;/div&gt; &lt;p&gt;Even though I get only text on screen the actual object returned is much more complex. I can demonstrate this by piping the object into another cmdlet.&lt;/p&gt; &lt;h1&gt;Piping&lt;/h1&gt; &lt;p&gt;A simple MS-DOS piping example would be &lt;span class="InlineCode"&gt;type file.txt | more&lt;/span&gt;. Actually you can use &lt;span class="InlineCode"&gt;more&lt;/span&gt; in PowerShell as well, but let’s look at another, more interesting cmdlet that we could pipe the object into; &lt;span class="InlineCode"&gt;Format-List&lt;/span&gt;.&lt;/p&gt; &lt;h2&gt;Format-List&lt;/h2&gt; &lt;p&gt;By default the output of Get-ChildItem is formatted in a table, but let’s say we want it as a list instead? No problem. Simply use the following syntax:&lt;/p&gt; &lt;div class="SampleCode"&gt;PS C:\Test&amp;gt; dir | format-list &lt;br&gt;&amp;nbsp;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Directory: Microsoft.PowerShell.Core\FileSystem::C:\Test &lt;br&gt;&amp;nbsp;&lt;br&gt;Name&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : Document.doc&lt;br&gt;Length&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : 45568&lt;br&gt;CreationTime&amp;nbsp;&amp;nbsp; : 2008-05-28 11:22:53&lt;br&gt;LastWriteTime&amp;nbsp; : 2008-05-28 11:25:26&lt;br&gt;LastAccessTime : 2008-05-28 11:25:26&lt;br&gt;VersionInfo&amp;nbsp;&amp;nbsp;&amp;nbsp; : &lt;br&gt;&amp;nbsp;&lt;br&gt;Name&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : Satisfaction.mp3&lt;br&gt;Length&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : 8993629&lt;br&gt;CreationTime&amp;nbsp;&amp;nbsp; : 2008-05-28 11:24:33&lt;br&gt;LastWriteTime&amp;nbsp; : 2008-05-26 10:00:46&lt;br&gt;LastAccessTime : 2008-05-28 11:24:33&lt;br&gt;VersionInfo&amp;nbsp;&amp;nbsp;&amp;nbsp; : &lt;br&gt;&amp;nbsp;&lt;br&gt;Name&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : Text.txt&lt;br&gt;Length&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : 1599&lt;br&gt;CreationTime&amp;nbsp;&amp;nbsp; : 2008-05-28 11:22:53&lt;br&gt;LastWriteTime&amp;nbsp; : 2008-05-28 11:25:35&lt;br&gt;LastAccessTime : 2008-05-28 11:22:53&lt;br&gt;VersionInfo&amp;nbsp;&amp;nbsp;&amp;nbsp; :&lt;/div&gt; &lt;p&gt;We still have the default information, only presented in a different manner. Still, there is a lot more information we could get, by using the &lt;span class="InlineCode"&gt;–property&lt;/span&gt; switch. By simply using the following syntax: &lt;span class="InlineCode"&gt;dir | format-list –property *&lt;/span&gt; we get &lt;em&gt;all&lt;/em&gt; the properties of each and every item in the directory. The output is quite extensive:&lt;/p&gt; &lt;div class="SampleCode"&gt;PS C:\Test&amp;gt; dir | format-list -property * &lt;br&gt;&amp;nbsp;&lt;br&gt;PSPath&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : Microsoft.PowerShell.Core\FileSystem::C:\Test\Document.doc&lt;br&gt;PSParentPath&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : Microsoft.PowerShell.Core\FileSystem::C:\Test&lt;br&gt;PSChildName&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : Document.doc&lt;br&gt;PSDrive&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : C&lt;br&gt;PSProvider&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : Microsoft.PowerShell.Core\FileSystem&lt;br&gt;PSIsContainer&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : False&lt;br&gt;Mode&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : -a---&lt;br&gt;Name&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : Document.doc&lt;br&gt;Length&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : 45568&lt;br&gt;DirectoryName&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : C:\Test&lt;br&gt;Directory&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : C:\Test&lt;br&gt;IsReadOnly&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : False&lt;br&gt;Exists&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : True&lt;br&gt;FullName&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : C:\Test\Document.doc&lt;br&gt;Extension&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : .doc&lt;br&gt;CreationTime&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : 2008-05-28 11:22:53&lt;br&gt;CreationTimeUtc&amp;nbsp;&amp;nbsp; : 2008-05-28 09:22:53&lt;br&gt;LastAccessTime&amp;nbsp;&amp;nbsp;&amp;nbsp; : 2008-05-28 11:25:26&lt;br&gt;LastAccessTimeUtc : 2008-05-28 09:25:26&lt;br&gt;LastWriteTime&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : 2008-05-28 11:25:26&lt;br&gt;LastWriteTimeUtc&amp;nbsp; : 2008-05-28 09:25:26&lt;br&gt;Attributes&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : Archive &lt;br&gt;&amp;nbsp;&lt;br&gt;PSPath&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : Microsoft.PowerShell.Core\FileSystem::C:\Test\Satisfaction.mp3&lt;br&gt;PSParentPath&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : Microsoft.PowerShell.Core\FileSystem::C:\Test&lt;br&gt;PSChildName&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : Satisfaction.mp3&lt;br&gt;PSDrive&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : C&lt;br&gt;PSProvider&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : Microsoft.PowerShell.Core\FileSystem&lt;br&gt;PSIsContainer&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : False&lt;br&gt;Mode&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : -a---&lt;br&gt;Name&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : Satisfaction.mp3&lt;br&gt;Length&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : 8993629&lt;br&gt;DirectoryName&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : C:\Test&lt;br&gt;Directory&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : C:\Test&lt;br&gt;IsReadOnly&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : False&lt;br&gt;Exists&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : True&lt;br&gt;FullName&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : C:\Test\Satisfaction.mp3&lt;br&gt;Extension&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : .mp3&lt;br&gt;CreationTime&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : 2008-05-28 11:24:33&lt;br&gt;CreationTimeUtc&amp;nbsp;&amp;nbsp; : 2008-05-28 09:24:33&lt;br&gt;LastAccessTime&amp;nbsp;&amp;nbsp;&amp;nbsp; : 2008-05-28 11:24:33&lt;br&gt;LastAccessTimeUtc : 2008-05-28 09:24:33&lt;br&gt;LastWriteTime&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : 2008-05-26 10:00:46&lt;br&gt;LastWriteTimeUtc&amp;nbsp; : 2008-05-26 08:00:46&lt;br&gt;Attributes&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : Archive &lt;br&gt;&amp;nbsp;&lt;br&gt;PSPath&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : Microsoft.PowerShell.Core\FileSystem::C:\Test\Text.txt&lt;br&gt;PSParentPath&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : Microsoft.PowerShell.Core\FileSystem::C:\Test&lt;br&gt;PSChildName&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : Text.txt&lt;br&gt;PSDrive&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : C&lt;br&gt;PSProvider&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : Microsoft.PowerShell.Core\FileSystem&lt;br&gt;PSIsContainer&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : False&lt;br&gt;Mode&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : -a---&lt;br&gt;Name&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : Text.txt&lt;br&gt;Length&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : 1599&lt;br&gt;DirectoryName&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : C:\Test&lt;br&gt;Directory&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : C:\Test&lt;br&gt;IsReadOnly&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : False&lt;br&gt;Exists&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : True&lt;br&gt;FullName&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : C:\Test\Text.txt&lt;br&gt;Extension&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : .txt&lt;br&gt;CreationTime&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : 2008-05-28 11:22:53&lt;br&gt;CreationTimeUtc&amp;nbsp;&amp;nbsp; : 2008-05-28 09:22:53&lt;br&gt;LastAccessTime&amp;nbsp;&amp;nbsp;&amp;nbsp; : 2008-05-28 11:22:53&lt;br&gt;LastAccessTimeUtc : 2008-05-28 09:22:53&lt;br&gt;LastWriteTime&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : 2008-05-28 11:25:35&lt;br&gt;LastWriteTimeUtc&amp;nbsp; : 2008-05-28 09:25:35&lt;br&gt;Attributes&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : Archive&lt;/div&gt; &lt;p&gt;As long as something is returned it is possible to daisy-chain additional cmdlets onto the previous one. We could, for example, add &lt;span class="InlineCode"&gt;| more&lt;/span&gt; to the command above to divide it into smaller chunks. We could use the Out-File cmdlet to save the result to a textfile, etc.&lt;/p&gt; &lt;h1&gt;Summary&lt;/h1&gt; &lt;p&gt;What have we covered so far?&lt;/p&gt; &lt;ul&gt; &lt;li&gt;PowerShell is object-oriented  &lt;li&gt;By default any object will be displayed on screen, so if you want to know what 2+2 equals, simply type &lt;span class="InlineCode"&gt;2+2&lt;/span&gt;.  &lt;li&gt;You can call standard .exe applications, etc from PowerShell, but they either need to be in the PATH, or you need to write the full path to them.  &lt;li&gt;PowerShell-specific applications are called cmdlets (“&lt;em&gt;Command-lets&lt;/em&gt;”)  &lt;li&gt;Most MS-DOS commands work, but they’re usually aliases to their PowerShell equivalent, so you might not be able to use all the switches you’re used to.  &lt;li&gt;You can use the | to daisy-chain cmdlets together, such as dir | format-list | more&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;We still haven’t covered things like functions, variables, creating .NET objects, etc. I also plan to write a few samples showing how to use the cool cmdlets to get information from computers on the network, looking for specific files, exporting to Excel, printing, etc. As always I’d be happy to receive feedback and suggestions on things to cover.&lt;/p&gt; &lt;p&gt;/ Johan&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8556478" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/johan/archive/tags/PowerShell/default.aspx">PowerShell</category></item></channel></rss>