<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>PowerShell</title>
        <link>http://www.darrinbishop.com/blog/category/1.aspx</link>
        <description>Posts releated to Microsoft PowerShell. </description>
        <language>en-US</language>
        <copyright>Darrin Bishop</copyright>
        <managingEditor>dbishop@darrinbishop.com</managingEditor>
        <generator>Subtext Version 1.9.4.78</generator>
        <item>
            <title>Speed up PowerShell Startup</title>
            <link>http://darrinbishop.com/blog/archive/2008/07/15/NGenPowerShellTip.aspx</link>
            <description>&lt;font face="Arial"&gt;&lt;font face="Tahoma" size="3"&gt;I caught this little gem (&lt;a target="_blank" href="http://blogs.msdn.com/powershell/archive/2007/11/08/update-gac-ps1.aspx"&gt;Update-Gac.ps1&lt;/a&gt;) on the &lt;a target="_blank" href="http://blogs.msdn.com/powershell"&gt;PowerShell Team blog&lt;/a&gt; while I was catching up on posts. This script will Ngen the PowerShell assemblies for a quicker start up. Ngen is a .NET utility that will create a native images that are stored in a cache which can be then used by the framework alleviating some of the JIT-ing at startup. I ran this script and noticed a big difference in the start up times. I will run this on all my machines.&lt;/font&gt;  &lt;/font&gt;&lt;img src="http://darrinbishop.com/blog/aggbug/103.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Darrin Bishop</dc:creator>
            <guid>http://darrinbishop.com/blog/archive/2008/07/15/NGenPowerShellTip.aspx</guid>
            <pubDate>Tue, 15 Jul 2008 21:47:44 GMT</pubDate>
            <comments>http://darrinbishop.com/blog/archive/2008/07/15/NGenPowerShellTip.aspx#feedback</comments>
            <wfw:commentRss>http://darrinbishop.com/blog/comments/commentRss/103.aspx</wfw:commentRss>
            <trackback:ping>http://darrinbishop.com/blog/services/trackbacks/103.aspx</trackback:ping>
        </item>
        <item>
            <title>GetActiveFeatureDefinitions - A SharePoint PowerShell Function </title>
            <link>http://darrinbishop.com/blog/archive/2008/07/14/GetActiveFeatureDefinitions.aspx</link>
            <description>&lt;p&gt;&lt;font face="Tahoma" size="3"&gt;Here is one more feature-related PowerShell script to quickly display which features are active based on a given SharePoint url. This script takes a SharePoint end point (url) as the first parameter and optional exclude parameters for each of the possible feature scopes.  This function will output SPFeatureDefinition objects that will display in the PowerShell host or can be used further in the pipeline as SPFeatureDefinitions. &lt;br /&gt;
 &lt;br /&gt;
I want to point out that this function returns SPFeatureDefinition objects as the function name suggests. Why do I return SPFeatureDefintion objects? Simple, the SPFarm object does not contain a collection of activated features while all the other scopes (WebApplication, Site, and Web) do. There is no SPFeature to retrieve from the SPFarm, all intstalled features scoped for the farm are active.  Since I use this function as a simple and quick way to see what features are activated based on the url endpoint I really only need the feature definition which contains the interesting properties including displayname, scope and hidden.&lt;br /&gt;
 &lt;br /&gt;
Now one warning - this function simply determines which features are activated based on the url end point. This does not mean that the feature directly affect the particular web or site. Some features are scoped at the farm or web app for a particular end point but does not manifest itself in the site or web.  For example, you might find publishing features listed as active when you are looking at a team site. Even though the team site is not using publishing features the feature is still activated for the farm or web application.  For this reason I included parameters that allow you to exclude features scoped at a particular level. &lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;&lt;font face="Tahoma" size="3"&gt;To use this function you must load the Microsoft.SharePoint assembly into your PowerShell host. To load the SharePoint Assembly in a PowerShell session type and run the following command:&lt;br /&gt;
 &lt;br /&gt;
&lt;font face="Courier New" color="#000080"&gt;[Reflection.Assembly]::Load("Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c")&lt;br /&gt;
&lt;/font&gt; &lt;br /&gt;
And now the function:&lt;br /&gt;
  &lt;br /&gt;
&lt;font face="Courier New" color="#333399"&gt;function GetActiveFeatureDefinitions&lt;br /&gt;
{&lt;br /&gt;
   param ([String] $webUrl,&lt;br /&gt;
              [Switch] $ExcludeFarm,&lt;br /&gt;
              [Switch] $ExcludeWebApp,&lt;br /&gt;
              [Switch] $ExcludeSite,&lt;br /&gt;
              [Switch] $ExcludeWeb )&lt;br /&gt;
   &lt;br /&gt;
   $site = new-object Microsoft.SharePoint.SPSite $webUrl&lt;br /&gt;
   $web = $site.OpenWeb()&lt;br /&gt;
   $webAPP =  $site.WebApplication&lt;br /&gt;
   $Farm = $WebApp.Farm&lt;br /&gt;
   &lt;br /&gt;
   if(!$ExcludeWeb.IsPresent)&lt;br /&gt;
   { $featureDefs = $web.features | %{$_.Definition}}&lt;br /&gt;
   &lt;br /&gt;
   if(!$ExcludeSite.IsPresent)&lt;br /&gt;
   { $featureDefs += $site.features | %{$_.Definition}}&lt;br /&gt;
   &lt;br /&gt;
   if(!$ExcludeWebApp.IsPresent)&lt;br /&gt;
   { $featureDefs += $webApp.features | foreach-object{$_.Definition}}&lt;br /&gt;
   &lt;br /&gt;
   if(!$ExcludeFarm.IsPresent)&lt;br /&gt;
   { $featureDefs += $farm.FeatureDefinitions | Where-Object{$_.Scope -eq 'Farm'}}&lt;br /&gt;
   &lt;br /&gt;
   $web.Dispose&lt;br /&gt;
   $site.Dispose&lt;br /&gt;
   return $featureDefs&lt;br /&gt;
}&lt;br /&gt;
&lt;/font&gt; &lt;br /&gt;
Here are some example uses of GetActiveFeatureDefintions:&lt;br /&gt;
 &lt;br /&gt;
&lt;font face="Courier New" color="#333399"&gt;GetActiveFeatureDefinitions http://localhost   &lt;br /&gt;
GetActiveFeatureDefinitions http://localhost  -excludeFarm      &lt;br /&gt;
GetActiveFeatureDefinitions http://localhost  -excludeFarm -excludeWebApp&lt;/font&gt;&lt;br /&gt;
 &lt;br /&gt;
Remember the function exports SPFeatureDefinition objects and can be used in the pipeline. Here are a few examples to try: &lt;br /&gt;
 &lt;br /&gt;
&lt;font face="Courier New" color="#333399"&gt;$fds= GetActiveFeatureDefinitions http://localhost -excludeFarm &lt;br /&gt;
$fds.count&lt;br /&gt;
 &lt;br /&gt;
GetActiveFeatureDefinitions http://localhost -excludeFarm   | Sort-Object Scope | Format-Table DisplayName, Scope, Hidden, Id -auto&lt;br /&gt;
 &lt;br /&gt;
GetActiveFeatureDefinitions http://localhost | Where-Object{$_.Hidden -eq $true} |Sort-Object Scope | Format-Table DisplayName, Scope, Hidden, Id -auto&lt;br /&gt;
&lt;/font&gt;&lt;/font&gt;  &lt;/font&gt;&lt;/p&gt;&lt;img src="http://darrinbishop.com/blog/aggbug/100.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Darrin Bishop</dc:creator>
            <guid>http://darrinbishop.com/blog/archive/2008/07/14/GetActiveFeatureDefinitions.aspx</guid>
            <pubDate>Mon, 14 Jul 2008 05:49:23 GMT</pubDate>
            <comments>http://darrinbishop.com/blog/archive/2008/07/14/GetActiveFeatureDefinitions.aspx#feedback</comments>
            <wfw:commentRss>http://darrinbishop.com/blog/comments/commentRss/100.aspx</wfw:commentRss>
            <trackback:ping>http://darrinbishop.com/blog/services/trackbacks/100.aspx</trackback:ping>
        </item>
        <item>
            <title>GetFeatureAndDependencies  - A SharePoint PowerShell Function</title>
            <link>http://darrinbishop.com/blog/archive/2008/07/06/GetFeatureDefinition.aspx</link>
            <description>&lt;p&gt;&lt;font face="Tahoma" size="3"&gt;As stated in my previous post, &lt;/font&gt;&lt;a target="_blank" href="http://www.darrinbishop.com/blog/archive/2008/07/02/95.aspx"&gt;&lt;font face="Tahoma" size="3"&gt;GetFeatureDefinition - A SharePoint PowerShell Function&lt;/font&gt;&lt;/a&gt;&lt;font face="Tahoma" size="3"&gt;, I have been  working on deploying a solution that contained multiple features which lead me down the road of feature activation dependencies. My current client's hosting environment has me looking to see just what I can pull off with hidden features and cross-scope dependencies.  In searching out any best practices around solution and feature packaging Scott Hillier suggested that I dig into the MOSS publishing features  to  look at how they relied on Activation Dependencies.   I just happened to be reading AC's &lt;/font&gt;&lt;a target="_blank" href="http://www.amazon.com/Professional-SharePoint-Content-Management-Development/dp/0470224754/ref=pd_bbs_sr_1?ie=UTF8&amp;amp;s=books&amp;amp;qid=1215399863&amp;amp;sr=8-1"&gt;&lt;font face="Tahoma" size="3"&gt;Professional WCM book, SharePoint 2007 Web Content Management Development&lt;/font&gt;&lt;/a&gt;&lt;font face="Tahoma" size="3"&gt;,  where Andrew  just happens to be discussing the publishing features. &lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Tahoma" size="3"&gt;So what I really wanted to do was to view some key information about a feature  and it's dependencies, for a given feature show me it's dependency to include name, id, scope and hidden property   If you have not tried to do this - well it is a time-consuming process when you must wade through  the feature directory  matching up feature activation ids to features.  &lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Tahoma" size="3"&gt;In my previous life , lets call it BPS (Before PowerShell), I like many developers would have opened up Visual Studio, started a new console project to created a simple application that would dump the features to the screen.  A typical one-shot app.  But now APS (After PowerShell) I took a few minutes and created a new SharePoint PowerShell function named  GetFeatureAndActivationDependencies which outputs to the screen key properties of the feature and any activation dependencies.&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Tahoma" size="3"&gt;So a little housekeeping before the script. First this script relies on the GetFeatureDefintion function in my last post, &lt;/font&gt;&lt;a target="_blank" href="http://www.darrinbishop.com/blog/archive/2008/07/02/95.aspx"&gt;&lt;font face="Tahoma" size="3"&gt;GetFeatureDefinition - A SharePoint PowerShell Function&lt;/font&gt;&lt;/a&gt;&lt;font face="Tahoma" size="3"&gt;. Make sure you add this function to your PowerShell host, either in the host itself or via  a profile. Next, both GetFeatureDefintion and GetFeatureDefintionAndDependencies must run in a PowerShell host on a WSS 3 or MOSS 2007 server. Finally as stated in all my PowerShell and SharePoint post you must load the SharePoint assembly in the PowerShell environment before you use these functions. To  include the SharePoint assembly in the PowerShell environment simply  execute the following command in PowerShell:&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New" color="#000080" size="3"&gt;[Reflection.Assembly]::Load("Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c")&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Tahoma" size="3"&gt;PowerShell will respond with information about the newly loaded assembly.&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Tahoma" size="3"&gt;So here is the function. It must be run on a WSS 3 or MOSS server  with PowerShell&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New" color="#000080" size="3"&gt;function GetFeatureAndDependencies&lt;br /&gt;
{&lt;br /&gt;
 Param([String] $FeatureId)&lt;br /&gt;
  &lt;br /&gt;
 getFeatureDefinition $FeatureId | sort-object{$_.DisplayName} | &lt;br /&gt;
 foreach-object{&lt;br /&gt;
   "Feature Definition`n-----------------------------------------------------------"&lt;br /&gt;
    $_ | format-table DisplayName, Id, Scope, Hidden -AutoSize&lt;br /&gt;
  &lt;br /&gt;
    $dep = $_.ActivationDependencies | foreach-object{getFeatureDefinition $_.FeatureId} | FT DisplayName, Id, Scope, Hidden -AutoSize&lt;br /&gt;
    if($dep -ne $null)&lt;br /&gt;
    {  &lt;br /&gt;
     "Activation Dependencies`n-----------------------------------------------------------"&lt;br /&gt;
      $dep &lt;br /&gt;
    }&lt;br /&gt;
    else&lt;br /&gt;
    {"No Dependencies"} &lt;br /&gt;
   }&lt;br /&gt;
}&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Tahoma" size="3"&gt;Once the function has been defined in your PowerShell session try  the following commands:&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New" color="#000080" size="3"&gt;GetFeatureAndDependencies&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Tahoma" size="3"&gt;Ok that is a little messy, it will dump every Feature Definition along with any activation dependencies.  This next command is "real-world" example.  All I have been provided is a Feature Definition id….And to make it more real, I don’t  know which feature maps to this ID.&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New" color="#000080" size="3"&gt;GetFeatureAndDependencies F6924D36-2FA8-4f0b-B16D-06B7250180FA&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Tahoma" size="3"&gt;To close this post, this is an example of a PowerShell script that provides a formatted output  to the screen for a report-like view. This script really was not intended to be used as input into another command. The script does not output a clean set of objects.&lt;br /&gt;
&lt;/font&gt;&lt;/p&gt;&lt;img src="http://darrinbishop.com/blog/aggbug/96.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Darrin Bishop</dc:creator>
            <guid>http://darrinbishop.com/blog/archive/2008/07/06/GetFeatureDefinition.aspx</guid>
            <pubDate>Mon, 07 Jul 2008 03:18:29 GMT</pubDate>
            <comments>http://darrinbishop.com/blog/archive/2008/07/06/GetFeatureDefinition.aspx#feedback</comments>
            <slash:comments>2</slash:comments>
            <wfw:commentRss>http://darrinbishop.com/blog/comments/commentRss/96.aspx</wfw:commentRss>
            <trackback:ping>http://darrinbishop.com/blog/services/trackbacks/96.aspx</trackback:ping>
        </item>
        <item>
            <title>GetFeatureDefinition - A SharePoint PowerShell Function</title>
            <link>http://darrinbishop.com/blog/archive/2008/07/02/95.aspx</link>
            <description>&lt;p&gt;&lt;font face="Arial" size="3"&gt;I cant believe I have not posted this simple PowerShell function. I have been doing some packaging of features and solutions lately so many of my feature-related scripts come to the foreground.&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial" size="3"&gt;The GetFeatureDefintion function will return either a single Feature Defintion (SPFeatureDefinition)  if you pass in a Feature Id or all feature definitions ( Array of Feature Definitions)  on the farm .  This is a great little function to include in your profile.  Before you attempt to use this function a little housekeeping is in order. First you need to run this in a &lt;font face="Tahoma"&gt;PowerShell session on a server that has WSS 3 or MOSS 2007. Next, you will need to load the SharePoint assembly into the PowerShell session. &lt;/font&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Tahoma" size="3"&gt;To load the SharePoint Assembly in a PowerShell session type and run the following command:&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font color="#0000ff" size="3"&gt;[&lt;font face="Courier New"&gt;Reflection.Assembly]::Load("Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c")&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Tahoma" size="3"&gt;PowerShell should respond with information about the assembly.&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Tahoma" size="3"&gt;And here is the script:&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New" color="#000080" size="3"&gt;function GetFeatureDefinition&lt;br /&gt;
{&lt;br /&gt;
  param($featureID="")&lt;br /&gt;
  $localFarm = [Microsoft.SharePoint.Administration.SPFarm]::Local&lt;br /&gt;
  if($featureID -ne "")&lt;br /&gt;
  {&lt;br /&gt;
    return $localFarm.FeatureDefinitions | where-object{$_.Id -eq $featureid}&lt;br /&gt;
  }&lt;br /&gt;
  else&lt;br /&gt;
  {&lt;br /&gt;
    return $localFarm.FeatureDefinitions&lt;br /&gt;
  }&lt;br /&gt;
}&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Tahoma" size="3"&gt;Once the function has been defined in your PowerShell session try  the following commands:&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New" color="#000080" size="3"&gt;GetFeatureDefinition&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New" color="#000080" size="3"&gt;GetFeatureDefinition  F6924D36-2FA8-4f0b-B16D-06B7250180FA&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Tahoma" size="3"&gt;Of course you can always format the output using format commands in PowerShell:&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Tahoma" size="3"&gt;&lt;font face="Courier New" color="#000080"&gt;GetFeatureDefinition | Format-Table  DisplayName, Id, Scope, Hidden&lt;br /&gt;
&lt;/font&gt;&lt;/font&gt;&lt;font face="Tahoma" size="3"&gt;&lt;font face="Courier New" color="#000080"&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Tahoma" size="3"&gt;&lt;font face="Courier New" color="#000080"&gt;GetFeatureDefinition   F6924D36-2FA8-4f0b-B16D-06B7250180FA | Format-Table  DisplayName, Id, Scope, Hidden&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Tahoma" size="3"&gt;And of course you can filter and sort using supplied PowerShell commands and the pipeline:&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New" color="#000080" size="3"&gt;GetFeatureDefinition | Where-Object{$_.DisplayName  -like 'Publish*'}  | Sort-Object Scope | FT  DisplayName, Id, Scope, Hidden&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Tahoma" size="3"&gt;Or&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New" color="#000080" size="3"&gt;GetFeatureDefinition | Where-Object{$_.Hidden -eq $True}  |Sort-Object DisplayName |  FT  DisplayName, Id, Scope, Hidden&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Tahoma" size="3"&gt;And don’t forget that with PowerShell you are working with objects:&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New" color="#000080" size="3"&gt;(GetFeatureDefinition | Where-Object{$_.DisplayName  -like 'Publish*'} ).Count&lt;br /&gt;
&lt;/font&gt;&lt;font face="Courier New" color="#000080" size="3"&gt;&lt;/font&gt;&lt;br /&gt;
&lt;font face="Courier New" color="#000080" size="3"&gt;(GetFeatureDefinition | Where-Object{$_.Hidden -eq  $True}).Count&lt;br /&gt;
&lt;/font&gt;&lt;/p&gt;&lt;img src="http://darrinbishop.com/blog/aggbug/95.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Darrin Bishop</dc:creator>
            <guid>http://darrinbishop.com/blog/archive/2008/07/02/95.aspx</guid>
            <pubDate>Thu, 03 Jul 2008 03:59:35 GMT</pubDate>
            <comments>http://darrinbishop.com/blog/archive/2008/07/02/95.aspx#feedback</comments>
            <wfw:commentRss>http://darrinbishop.com/blog/comments/commentRss/95.aspx</wfw:commentRss>
            <trackback:ping>http://darrinbishop.com/blog/services/trackbacks/95.aspx</trackback:ping>
        </item>
        <item>
            <title>Tech Ed 2008 - OFC07-TLC - Building Windows PowerShell Cmdlets for Microsoft SharePoint</title>
            <link>http://darrinbishop.com/blog/archive/2008/06/21/92.aspx</link>
            <description>&lt;p&gt;&lt;font face="Tahoma" size="4"&gt;For those that attended OFC07-TLC - Thanks!&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Tahoma" size="4"&gt;Here are the files and slide deck  for &lt;/font&gt;&lt;a target="_blank" href="http://www.darrinbishop.com/files/OFC07_TLC.zip"&gt;&lt;font face="Tahoma" size="4"&gt;OFC07-TLC  Building Windows PowerShell Cmdlets for Microsoft SharePoint&lt;/font&gt;&lt;/a&gt;&lt;font face="Tahoma" size="4"&gt;. The demo builds a simple Get-Web cmdlet and a Web Feature Provider.  Remember this is "conference" code and not production code :) demo purposes only!&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Tahoma" size="4"&gt;As always, I am interested in comments and feedback about the demo, slides, or session.&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Tahoma"&gt;&lt;font size="4"&gt;File: &lt;a href="http://www.darrinbishop.com/files/OFC07_TLC.zip"&gt;http://www.darrinbishop.com/files/OFC07_TLC.zip&lt;/a&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;&lt;img src="http://darrinbishop.com/blog/aggbug/92.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Darrin Bishop</dc:creator>
            <guid>http://darrinbishop.com/blog/archive/2008/06/21/92.aspx</guid>
            <pubDate>Sun, 22 Jun 2008 02:26:37 GMT</pubDate>
            <comments>http://darrinbishop.com/blog/archive/2008/06/21/92.aspx#feedback</comments>
            <wfw:commentRss>http://darrinbishop.com/blog/comments/commentRss/92.aspx</wfw:commentRss>
            <trackback:ping>http://darrinbishop.com/blog/services/trackbacks/92.aspx</trackback:ping>
        </item>
        <item>
            <title>Limiting Your SharePoint Objects with PowerShell</title>
            <link>http://darrinbishop.com/blog/archive/2008/03/17/SPWhereObject.aspx</link>
            <description>&lt;p&gt;&lt;font face="Arial"&gt;In my post "&lt;a target="_blank" href="http://www.darrinbishop.com/blog/archive/2007/11/28/psfivefunctions.aspx"&gt;Five Simple But Powerful PowerShell Functions/Filters for SharePoint&lt;/a&gt;" I demonstrated five functions and filters that when stung together  allowed you to access many of the key SharePoint objects. This post assumes you read Five Simple But Powerful PowerShell Functions/Filters for SharePoint.  The five functions and filters are interesting because we can access key SharePoint objects which we will  use later in scripts. The problem with the five functions and filters is they lack specificity. They will bring back every object of a specific type on the a SharePoint farm. In some cases this is what you want but in others it simply produces a lot of noise.&lt;br /&gt;
 &lt;br /&gt;
 I should throw in a note here that lets the readers know that I chose to "design" these functions and filters to be chain-able and return all the objects of a certain type . I certainly could have created functions and filters that would allow the reader to target a very specific object. By including limiting parameters.  I felt that design would have created more functions that would require parameters and might be more confusing to administrators that do not have much scripting experience. &lt;br /&gt;
 &lt;br /&gt;
Back to the topic of limiting  our output.  PowerShell has provided an important cmdlet, Where-Object,  that can be used for limiting  the output to the pipeline. Strategically placing this cmdlet  in our existing pipeline will control which objects continue through the pipeline  to the next cmdlet and ultimately the host (i.e. the console).  First lets look at the syntax for the Where-Object&lt;br /&gt;
 &lt;br /&gt;
Where-Object {  &amp;lt;Script Block&amp;gt; }&lt;br /&gt;
 &lt;br /&gt;
The Where-Object is standard cmdlet verb-noun syntax that we have seen before. The Script Block is new. The author of the PowerShell script provides a block of script that the Where-Object uses to select which objects makes it thought the pipeline.  Lets look at a very simple example again using the Get-Process cmdlet.&lt;br /&gt;
 &lt;br /&gt;
Now lets look at the output to the host when we execute  Get-Process ( the canonical demo example)&lt;br /&gt;
 &lt;img height="400" alt="Image of Get Process with no filter" hspace="2" width="600" vspace="2" border="2" src="\images\whereobject\GetProcessNoFilter.gif" /&gt;&lt;br /&gt;
 Output of Get-Process&lt;br /&gt;
 &lt;br /&gt;
Now compare the output when we execute  Get-Process | Where-Object { $_.ProcessName -like  "SQL*"}&lt;br /&gt;
 &lt;br /&gt;
 &lt;img height="202" alt="Output of a filtered  Get Process call" hspace="2" width="600" vspace="2" border="2" src="/images/whereobject/GetProcessWithFilter.gif" /&gt;&lt;br /&gt;
Output of Get-Process | Where-Object { $_.ProcessName -like  "SQL*"}&lt;br /&gt;
 &lt;br /&gt;
The second example containing the Where-Object cmdlet only passes objects though the pipeline when the current object (referenced by $_ )  has a ProcessName  property that begins with the string 'SQL' as defined in the scriptblock delineated by braces. All other objects passed via the pipeline to the Where-Object cmdlets  that does not meet the Where-Object criteria is dropped and not passed on to the next cmdlet in the pipeline. In this example is not passed to the default format cmdlet before being sent to the PowerShell console.&lt;br /&gt;
 &lt;br /&gt;
So now lets see how we can use the Where-Object to provide some selectivity for our 5 filters and functions.  These scripts assume you have followed the Five Simple But Powerful PowerShell Functions/Filters for SharePoint post.  Lets start with this example that will return all webs  (SPWeb objects) on the local farm  ( remember you must run this on a SharePoint server).&lt;br /&gt;
 &lt;br /&gt;
Get-localfarm |get-webservice | get-webapplication | get-sitecollection | get-web  | format-table title, url&lt;br /&gt;
 &lt;br /&gt;
  &lt;br /&gt;
 &lt;img height="345" alt="Output of get webs with no filter" hspace="2" width="800" vspace="2" border="2" src="\images\whereobject\WebsNoFilter.gif" /&gt;&lt;br /&gt;
Results of  Get-localfarm |get-webservice | get-webapplication | get-sitecollection | get-web  | format-table title, url&lt;br /&gt;
 &lt;br /&gt;
Now lets add a Where-Object cmdlet:&lt;br /&gt;
Get-localfarm |get-webservice | get-webapplication | get-sitecollection | get-web  | Where-Object{$_.url -like "*dev*"} | format-table title, url&lt;br /&gt;
 &lt;br /&gt;
&lt;img height="173" alt="output of Get Webs with Filter" hspace="2" width="800" vspace="2" border="2" src="/images/whereobject/WebsWithFilter.gif" /&gt;  &lt;br /&gt;
Results after piping to Where-Object{$_.url -like "*dev*"}&lt;br /&gt;
 &lt;br /&gt;
Notice we can now limit what webs are passed on to the next cmdlet.   In the last example we limited the SPWeb objects passed to the end of the pipeline to those that contained the substring 'dev'.&lt;br /&gt;
 &lt;br /&gt;
&lt;em&gt;&lt;font color="#ff0000"&gt;[Hint: Not sure what properties of the SPWeb objects to filter on? The Windows SharePoint Services SDK  has them all. Another way is to run the following:&lt;/font&gt;&lt;/em&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;&lt;em&gt;&lt;font color="#ff0000"&gt;$webs = Get-localfarm |get-webservice | get-webapplication | get-sitecollection | get-web  &lt;br /&gt;
$webs[0] | Get-Member&lt;br /&gt;
 &lt;br /&gt;
This set of cmdlets retrieves all the webs (SPWeb) objects on the local farm and places them in a variable ($webs). The second line will send the first SPWeb to the Get-Member cmdlet and dump the properties and methods to the screen]&lt;br /&gt;
&lt;/font&gt;&lt;/em&gt; &lt;br /&gt;
Try running this set of cmdlets:&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;Get-localfarm |get-webservice | get-webapplication | get-sitecollection | get-web  | Where-Object{$_.webtemplate  -eq  'Wiki'} | format-table  title, url, WebTemplate&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;&lt;img height="157" alt="" hspace="2" width="800" vspace="2" border="2" src="/images/whereobject/WebsAreWiki.gif" /&gt;&lt;br /&gt;
 &lt;br /&gt;
You will display the title, url and WebTemplate  values for webs that were created from the Wiki template.&lt;br /&gt;
 &lt;br /&gt;
Need to get a list of all the team site  webs? Try:&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;Get-localfarm |get-webservice | get-webapplication | get-sitecollection | get-web  | Where-Object{$_.webtemplate  -eq 'STS'} | format-table  title, url, WebTemplate&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;&lt;img height="222" alt="Image of get web with a filter for STS" hspace="2" width="800" vspace="2" border="2" src="/images/whereobject/WebsAreSTS.gif" /&gt;&lt;br /&gt;
 &lt;br /&gt;
How about a list of all webs that allow anonymous access? Try:&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;Get-localfarm |get-webservice | get-webapplication | get-sitecollection | get-web  | Where-Object{$_.allowAnoymousAccess -eq $true} | format-table  title, url, WebTemplate&lt;br /&gt;
 &lt;br /&gt;
Now a list of site collections:&lt;br /&gt;
Get-localfarm |get-webservice | get-webapplication | get-sitecollection | format-table url, owner&lt;br /&gt;
 &lt;br /&gt;
And now only site collections on port 8090&lt;br /&gt;
Get-localfarm |get-webservice | get-webapplication |Where-Object {$_.Port -eq 8090} | format-table url, owner&lt;br /&gt;
 &lt;br /&gt;
Now expand the last set of cmdlets to include a get-web before you end with Format-Table and you will get all webs for site collections on port 8090.&lt;br /&gt;
 &lt;br /&gt;
Get-localfarm |get-webservice | get-webapplication | get-sitecollection | Where-Object {$_.Port -eq 8090} | get-web | format-table title, url&lt;br /&gt;
 &lt;br /&gt;
Ok, these are very simple examples of limiting the output from our five filters and functions. Working with the Get-Member cmdlet or the SDK will allow you to effectively filter and cut down on the noise. &lt;/font&gt;&lt;/p&gt;&lt;img src="http://darrinbishop.com/blog/aggbug/84.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Darrin Bishop</dc:creator>
            <guid>http://darrinbishop.com/blog/archive/2008/03/17/SPWhereObject.aspx</guid>
            <pubDate>Mon, 17 Mar 2008 14:41:26 GMT</pubDate>
            <comments>http://darrinbishop.com/blog/archive/2008/03/17/SPWhereObject.aspx#feedback</comments>
            <wfw:commentRss>http://darrinbishop.com/blog/comments/commentRss/84.aspx</wfw:commentRss>
            <trackback:ping>http://darrinbishop.com/blog/services/trackbacks/84.aspx</trackback:ping>
        </item>
        <item>
            <title>Find Me at the Bloomington .Net User Group</title>
            <link>http://darrinbishop.com/blog/archive/2007/12/17/81.aspx</link>
            <description>&lt;p&gt;&lt;font face="Arial"&gt;Find me in Bloomington, Illinois in January.  I will be speaking at the  Bloomington .NET User Group on January 8 2008. I will be covering SharePoint and PowerShell  ( one of my favorite subjects ).  For those of you in the Central Illinois area please stop by.&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;Get the details at:  &lt;a target="_blank" href="http://bloomingtondotnet.org/"&gt;http://bloomingtondotnet.org/&lt;/a&gt;&lt;/font&gt;&lt;/p&gt;&lt;img src="http://darrinbishop.com/blog/aggbug/81.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Darrin Bishop</dc:creator>
            <guid>http://darrinbishop.com/blog/archive/2007/12/17/81.aspx</guid>
            <pubDate>Tue, 18 Dec 2007 02:53:16 GMT</pubDate>
            <comments>http://darrinbishop.com/blog/archive/2007/12/17/81.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://darrinbishop.com/blog/comments/commentRss/81.aspx</wfw:commentRss>
            <trackback:ping>http://darrinbishop.com/blog/services/trackbacks/81.aspx</trackback:ping>
        </item>
        <item>
            <title>Five Simple But Powerful PowerShell Functions/Filters for SharePoint</title>
            <link>http://darrinbishop.com/blog/archive/2007/11/28/psfivefunctions.aspx</link>
            <description>&lt;p align="justify"&gt;&lt;font face="Arial"&gt;To start out, a function in PowerShell  is similar to a function in any  other development language. &lt;font face="Arial"&gt;(See my last post  "&lt;a target="_blank" href="http://darrinbishop.com/blog/archive/2007/11/27/PowerShellCommands.aspx"&gt;Commands in PowerShell&lt;/a&gt;" for a little PowerShell basics on command and functions.) &lt;/font&gt; It takes zero or more inputs,  runs zero or more statements and possibly returns one or more values.  Functions in PowerShell are a way to gather up multiple statements into a functional, reusable piece of code.  Below is a shell of a basic function in PowerShell.&lt;/font&gt;&lt;/p&gt;
&lt;p align="justify"&gt;&lt;font face="Arial"&gt;Function DoThis($var)&lt;br /&gt;
{&lt;br /&gt;
   &amp;lt;Statements&amp;gt;&lt;br /&gt;
}&lt;/font&gt;&lt;/p&gt;
&lt;p align="justify"&gt;&lt;font face="Arial"&gt;What exactly is a PowerShell filter? A filter is very similar to a function with the exception of the filter  keyword. &lt;/font&gt;&lt;/p&gt;
&lt;p align="justify"&gt;&lt;font face="Arial"&gt;Filter DoThat($var)&lt;br /&gt;
{&lt;br /&gt;
   &amp;lt;Statements&amp;gt;&lt;br /&gt;
}&lt;/font&gt;&lt;/p&gt;
&lt;p align="justify"&gt;&lt;font face="Arial"&gt;Both functions and filters can participate in the PowerShell pipeline but they do so in slightly different ways. (&lt;a target="_blank" href="http://darrinbishop.com/blog/archive/2007/04/08/54.aspx"&gt;&lt;font face="Arial"&gt;To read about the pipeline..&lt;/font&gt; &lt;/a&gt;) The  PowerShell pipeline provides the ability to stream the output of one command as input to the next command via the pipe character  |.  Functions (simple functions)  can access the current object in the pipeline using the $Input value and run till completion. Filters access the current object in the pipeline using the $_ variable and run once per object placed in the pipeline. There is a slight but real difference between how a function and filter work but suffice it to say that in simplistic terms Filters work nicer with the pipeline . ( Ok, that is not completely true. There is a way to create a function that will work like a filter but that is not the focus of this post and using filters saves me a few lines of code.)&lt;/font&gt;&lt;/p&gt;
&lt;font face="Arial"&gt;
&lt;p align="justify"&gt;So here are my simple  functions and filters that I end up using all the time. &lt;/p&gt;
&lt;p align="justify"&gt;function Get-LocalFarm&lt;br /&gt;
{&lt;br /&gt;
   return [Microsoft.SharePoint.Administration.SPFarm]::Local&lt;br /&gt;
}&lt;/p&gt;
&lt;p align="justify"&gt;filter Get-WebService&lt;br /&gt;
{&lt;br /&gt;
   $webServices = new-object  Microsoft.SharePoint.Administration.SPWebServiceCollection($_)&lt;br /&gt;
   $webServices&lt;br /&gt;
}&lt;/p&gt;
&lt;p align="justify"&gt;filter Get-WebApplication&lt;br /&gt;
{&lt;br /&gt;
   $_.WebApplications&lt;br /&gt;
}&lt;/p&gt;
&lt;p align="justify"&gt;filter Get-SiteCollection &lt;br /&gt;
{&lt;br /&gt;
   $_.Sites&lt;br /&gt;
}&lt;/p&gt;
&lt;p align="justify"&gt;filter Get-Web &lt;br /&gt;
{&lt;br /&gt;
   $_.AllWebs&lt;br /&gt;
}&lt;/p&gt;
&lt;p align="justify"&gt;Did I not say they were simple? So what is the big deal about these function and  filters?  Figure 1 below displays a simple view of a SharePoint Farm object hierarchy. The above  five functions and filters allow us to access all of the objects show in Figure 1.&lt;br /&gt;
&lt;img height="648" alt="" hspace="10" width="398" align="bottom" vspace="10" border="0" src="/images/psFiveFunctions/SPHierarchy.jpg" /&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;&lt;strong&gt;Figure 1:&lt;/strong&gt; &lt;em&gt;Basic SharePoint Object Model Hierarchy&lt;/em&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;If you compare the function/filters from above to the hierarchy in Figure 1  you will notice that there is a corresponding filter or function for each object level. &lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;It is very simple - Get-LocalFarm will return the SPFarm object.  If you pipe the SPFarm object to Get-SPWebService you will have access to all the SPWebServices associated with the local farm.  Chain all five function/filters together and the end result is ALL SPWeb objects on the farm.  Since these are small reusable pieces of code you can stop the chain where it makes sense.&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;Before I demonstrate how you can use these filters and functions let me explain how to set these up in PowerShell.&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;First you must be on a WSS 3.0 or MOSS 2007 server. Since the SharePoint object model does not remote you must run these from a PowerShell instance on the server. &lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;Next before you add the filters and functions to the PowerShell environment you must add the Microsoft.Sharepoint assembly to the PowerShell environment.  To add the Microsoft.SharePoint assembly to the PowerShell environment simply &lt;/font&gt;&lt;font face="Arial"&gt;run the following command in PowerShell :&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;[Reflection.Assembly]::Load(“Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c“)&lt;/font&gt;&lt;/p&gt;
&lt;p align="justify"&gt;&lt;font face="Arial"&gt;Next copy the function and filters listed above and paste into the PowerShell command window.  Since I used these all the time I have these listed in my profile.ps1 file so they load up automatically when I start PowerShell. Now you can use one or more of the function/filters to access any of the object model items shown in Figure 1. &lt;/font&gt;&lt;/p&gt;
&lt;p align="justify"&gt;Here are a few examples to play with:&lt;/p&gt;
&lt;p align="justify"&gt;get-localfarm&lt;br /&gt;
get-localfarm |get-webservice&lt;br /&gt;
get-localfarm |get-webservice | get-webapplication&lt;br /&gt;
get-localfarm |get-webservice | get-webapplication | get-sitecollection&lt;br /&gt;
get-localfarm |get-webservice | get-webapplication | get-sitecollection | get-web&lt;br /&gt;
 &lt;br /&gt;
The first example will output a text representation of the SPFarm object for the local farm.&lt;br /&gt;
The second example will output zero or more text representations of SPWebService objects associated with the farm.  You should be able to guess the objects passed out the pipeline based on the name of the filter.&lt;/p&gt;
&lt;p align="justify"&gt;If you actually executed the last statement in the list of  statements above you should have ended up with output similar to Figure 2.&lt;/p&gt;
&lt;p&gt;&lt;img height="356" alt="Screen shot of PowerShell output displaying a SPWeb object" hspace="10" width="600" align="bottom" vspace="10" border="0" src="/images/psFiveFunctions/SPWebOutput.jpg" /&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;&lt;strong&gt;Figure 2 :&lt;/strong&gt; &lt;em&gt;Screen shot of   get-localfarm |get-webservice | get-webapplication | get-sitecollection | get-web&lt;/em&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p align="justify"&gt;&lt;font face="Arial"&gt;In Figure 2 we see that the SPWeb objects hit the end of the pipeline and was formatted for the host providing us a view into the SPWeb object.  A view such as this is not real easy to review particularly when the out scrolls off the screen. So let's format the output so we can get a better view of the results.  For an SPWeb object  I like to view the URL.  We can pipe the SPWeb objects to the format-table cmdlet.  The new command looks like:&lt;/font&gt;&lt;/p&gt;
&lt;p align="justify"&gt;&lt;font face="Arial"&gt;Get-localfarm |get-webservice | get-webapplication | get-sitecollection | get-web |format-table   -property url&lt;/font&gt;&lt;/p&gt;
&lt;p align="justify"&gt;&lt;font face="Arial"&gt;and the new output looks like:&lt;/font&gt;&lt;/p&gt;
&lt;p&gt; &lt;img height="356" alt="Screen shot of PowerShell ouput of SPWeb objects using format table" hspace="10" width="600" align="bottom" vspace="10" border="0" src="/images/psfivefunctions/SPWebsFormatTable.jpg" /&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;&lt;strong&gt;Figure 3:&lt;/strong&gt; &lt;em&gt;SPWeb objects piped to Format-Table cmdlet&lt;/em&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p align="justify"&gt;&lt;font face="Arial"&gt;Figure 3 displays the output of the last set of commands. It shows all web objects on the farm.  Although we now only see the url of each SPWeb object sent to the format-table cmdlet we have access to properties and methods of the SPWeb object.  So now we have access to each SPWeb object in the farm as it passes though the pipeline. Since we have access to the actual SPWeb object we have access to all the properties and methods of that object and can script against it.  That's pretty powerful.&lt;/font&gt;&lt;/p&gt;
&lt;p align="justify"&gt;&lt;font face="Arial"&gt;Right now  I am sure it appears that there is a lot of noise in the output  but the next post we will continue to use these filters and functions   along with other PowerShell cmdlets to be more selective in the output. &lt;/font&gt;&lt;/p&gt;
&lt;p align="justify"&gt;&lt;font face="Arial"&gt;One last example for you to try&lt;br /&gt;
(get-localfarm).solutions | format-table -property name&lt;/font&gt;&lt;/p&gt;
&lt;p align="justify"&gt;&lt;font face="Arial"&gt;Yes this will output the name of all solutions installed on the farm&lt;/font&gt;&lt;/p&gt;
&lt;/font&gt;&lt;img src="http://darrinbishop.com/blog/aggbug/75.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Darrin Bishop</dc:creator>
            <guid>http://darrinbishop.com/blog/archive/2007/11/28/psfivefunctions.aspx</guid>
            <pubDate>Wed, 28 Nov 2007 17:46:19 GMT</pubDate>
            <comments>http://darrinbishop.com/blog/archive/2007/11/28/psfivefunctions.aspx#feedback</comments>
            <slash:comments>2</slash:comments>
            <wfw:commentRss>http://darrinbishop.com/blog/comments/commentRss/75.aspx</wfw:commentRss>
            <trackback:ping>http://darrinbishop.com/blog/services/trackbacks/75.aspx</trackback:ping>
        </item>
        <item>
            <title>Commands in PowerShell</title>
            <link>http://darrinbishop.com/blog/archive/2007/11/27/PowerShellCommands.aspx</link>
            <description>&lt;p&gt;&lt;font face="Arial"&gt;Commands do the work in PowerShell. Its that simple yet when I speak about PowerShell and SharePoint there always seems to be some confusion on what a command is.  That's understandable because in PowerShell there are many ways to execute a command.  Yesterday I was speaking with someone and started talking about functions and filters in PowerShell. The person whom I was speaking with had not worked with functions or filters but understood cmdlets and providers.&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;It seems that if I want to create posts on PowerShell and SharePoint I need to preface it with a post on commands.  This way as you read my PS/SP posts you can better understand the commands I use. Don't consider this "the" blog post on PowerShell commands but a simple primer to help clear the ambiguities.&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;First commands  causes actions to happen in PowerShell.  Commands allow us to accomplish tasks from listing the files on a file system to opening a text file in notepad. The concept of a command in a "command line" application is not new and probably not confusing. What might be considered confusing is that PowerShell has four basic types of commands.  To make things a little more interesting commands of one type can interact with commands of other types.&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;The four basic command types in PowerShell are:&lt;br /&gt;
1)  Cmdlets&lt;br /&gt;
2)  Functions&lt;br /&gt;
3) Native&lt;br /&gt;
4) Scripts&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;&lt;strong&gt;Cmdlets&lt;/strong&gt;&lt;br /&gt;
The standard demo command for PowerShell appears to be get-process. Get-process cmdlet will ultimately dump process information to the host ( screen). Get-Process is a cmdlet (pronounced command-let). Cmdlets support a normalized naming scheme with the verb-noun syntax.  Cmdlets are compiled code that are available to the PowerShell environment.  PowerShell has "built-in" cmdlets such as get-process, get-help and where-object  to name a very few.  Developers can create new cmdlets and register them with the PowerShell host.  &lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;To run a simple cmdlet in PowerShell&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;1.  Open PowerShell&lt;br /&gt;
2.  Type Get-Process at the PowerShell Prompt.&lt;br /&gt;
3. Click Enter to execute the cmdlet.&lt;/font&gt;&lt;/p&gt;
&lt;font face="Arial"&gt;
&lt;p&gt;&lt;img height="171" alt="Cmdlet Example" hspace="10" width="500" align="bottom" vspace="10" border="0" src="/images/pscommands/CmdletExample.jpg" /&gt;&lt;br /&gt;
&lt;em&gt;&lt;strong&gt;Figure 1:&lt;/strong&gt;  Executing a Cmdlet in PowerShell Host&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Functions&lt;/strong&gt;&lt;br /&gt;
Functions  organize commands and statements into a reusable chunk of code.  Here is an example of a function in PowerShell:&lt;/p&gt;
&lt;p&gt;Function WriteDBGFooter&lt;br /&gt;
{&lt;br /&gt;
    "Darrin Bishop Group, Inc."&lt;br /&gt;
    "www.darrinbishop.com\blog"&lt;br /&gt;
}&lt;/p&gt;
&lt;p&gt;Functions are compiled when they are defined in the host and are generally available until you restart the host. Functions can take parameters.  &lt;/p&gt;
&lt;p&gt;To create and execute the WriteDBGFooter function defined above&lt;/p&gt;
&lt;p&gt;1. Type the function into the PowerShell Host&lt;br /&gt;
PowerShell allows you to add returns while typing. It is "smart enough" to know when the commands are complete. When it is expecting more characters it will display a &amp;gt;&amp;gt; prompt. So you are free to type in a multiline function without PowerShell attempting to execute a partial function.  You will need to type one more return at the end of the function to let PS know you are done entering the functions.&lt;br /&gt;
2. Type WriteDBGFooter&lt;br /&gt;
3. Press Enter to execute&lt;/p&gt;
&lt;p&gt;The result should be similar to Figure 2 below.  You should be able to use WriteDBGFooter for the life of the PowerShell session without rekeying the function.&lt;/p&gt;
&lt;p&gt;&lt;img height="215" alt="Screenshot example of a function" hspace="10" width="600" align="bottom" vspace="10" border="0" src="/images/pscommands/WriteDBGFooter.jpg" /&gt;&lt;br /&gt;
&lt;em&gt;&lt;strong&gt;Figure 2:&lt;/strong&gt; PowerShell Function Defined and Executed&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Native&lt;/strong&gt;&lt;br /&gt;
Native commands are simple. Native commands are those that run outside the PowerShell process. When you open a .docx file in Microsoft Word you are using a native command.&lt;/p&gt;
&lt;p&gt;To execute a Native command:&lt;/p&gt;
&lt;p&gt;1. In PowerShell host enter the path to a Word document &lt;br /&gt;
2. Enter to Execute&lt;/p&gt;
&lt;p&gt;Figure 3 and 4 below displays the PowerShell host and the resulting Word document.&lt;/p&gt;
&lt;p&gt; &lt;img height="148" alt="Screen shot of a native command in PowerShell" hspace="10" width="540" align="bottom" vspace="10" border="0" src="/images/pscommands/nativeCmdExample.jpg" /&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;Figure 3:&lt;/strong&gt;  Executing a Native Command&lt;/em&gt;&lt;/p&gt;
&lt;p&gt; &lt;img height="307" alt="Screen shot of a Word document" hspace="10" width="520" align="bottom" vspace="10" border="0" src="/images/pscommands/worddoc.jpg" /&gt;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;em&gt;&lt;strong&gt;Figure 4:&lt;/strong&gt;Document Opened in Word&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Scripts&lt;/strong&gt;&lt;br /&gt;
Script commands are simply commands that have been saved to the file system. Scripts are commonly saved with a .ps1 extension.  Scripts let us save a commonly used set of commands to a file so that we can run it many times without rekeying the script.  Scripts are called from PowerShell by file name. If your PowerShell's current location is the same as the location of the script you can execute the script by placing a ./ in front o the script name. The ./ is required when your current PowerShell location is the same as the script location. &lt;/p&gt;
&lt;p&gt;One other interesting thing to know about scripts is that scripts will not run by default. PowerShell allows you to set a script execution policy. By default scripts must be signed before they can run. By calling the  set-executionpolicy passing in unrestricted value you can bypass this security block. Ofcourse you should really think about what you are doing when you decide to do this. The PowerShell team placed this in the host for a reason.&lt;/p&gt;
&lt;p&gt;To set the Execution Policy&lt;/p&gt;
&lt;p&gt;1. Type  set-executionpolicy -ExecutionPolicy Unrestricted&lt;br /&gt;
2. Click Enter to execute.&lt;/p&gt;
&lt;p&gt;(Note, if you are running Vista you might need to run PowerShell as an administrator to make this policy change)&lt;/p&gt;
&lt;p&gt;To demonstrate a script I will explain how to create a script that looks at the Application event log and counts the number of Outlook events .&lt;/p&gt;
&lt;p&gt;1. Open Notepad&lt;br /&gt;
2. Type into Notepad the following commands&lt;/p&gt;
&lt;p&gt;$logItemCount =  (get-eventlog -logName Application | Where-Object {$_.Source -eq "Outlook"} ).count&lt;br /&gt;
"You have $logItemCount Outlook items in the Application event log."&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
3. Save the file as GetOutlookLogItems.ps1 . For this example I have saved GetOutlookLogItems.ps1 to c:\PSScripts.&lt;br /&gt;
4. Type c:\PSScripts\GetOutlookLogItems.ps1&lt;br /&gt;
5. Click Enter to execute&lt;/p&gt;
&lt;p&gt;Figure 5 displays the script in Notepad and Figure 6 displays the PowerShell console after executing the script.&lt;/p&gt;
&lt;p&gt; &lt;img height="117" alt="" hspace="10" width="700" align="bottom" vspace="10" border="0" src="/images/pscommands/ScriptInNotePad.jpg" /&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;Figure 5:&lt;/strong&gt;  Creating a Script&lt;/em&gt;&lt;/p&gt;
&lt;p&gt; &lt;img height="119" alt="Screen shot of a script run in PowerShell" hspace="10" width="700" align="bottom" vspace="10" border="0" src="/images/pscommands/ScriptOutput.jpg" /&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;Figure 6:&lt;/strong&gt; Executing a Script&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;That’s a very basic overview of the command types in PowerShell. I really boils down to executing commands in the PowerShell host regardless of the command type.  Cmdlets are great if there is one that works for your situations. I use functions a lot to script against an object model because I do not have to compile or register a function like a custom cmdlet ( I do build and use custom cmdlets when it suits me).  Functions are a great way to quickly encapsulate one or more commands for reuse  I use scripts to roll up many commands and functions to achieve a particular objective. With scripts I can create, test, fix and then reuse whenever I need the script. &lt;/p&gt;
&lt;/font&gt;&lt;img src="http://darrinbishop.com/blog/aggbug/74.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Darrin Bishop</dc:creator>
            <guid>http://darrinbishop.com/blog/archive/2007/11/27/PowerShellCommands.aspx</guid>
            <pubDate>Tue, 27 Nov 2007 14:58:22 GMT</pubDate>
            <comments>http://darrinbishop.com/blog/archive/2007/11/27/PowerShellCommands.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://darrinbishop.com/blog/comments/commentRss/74.aspx</wfw:commentRss>
            <trackback:ping>http://darrinbishop.com/blog/services/trackbacks/74.aspx</trackback:ping>
        </item>
        <item>
            <title>Barcelona, Spain PowerShell/SharePoint Scripts</title>
            <link>http://darrinbishop.com/blog/archive/2007/11/23/72.aspx</link>
            <description>&lt;p&gt;&lt;font face="Arial"&gt;As promised here are the PowerShell scripts I used in my session at ITForums in Barcelona Spain.  &lt;/font&gt;&lt;/p&gt;
&lt;p&gt; &lt;font face="Arial"&gt;&lt;a href="http://www.darrinbishop.com/files/PS_SPDemoCode.zip"&gt;PS_SPDemoCode.zip&lt;/a&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;If you want to follow along with the demo script  (demoScript.txt)  you must place the files in the correct location or change the included demo script.  Once the files are placed in the correct location on the SharePoint server  you can copy  and paste the commands from demoScript.txt to PowerShell. &lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;To setup the environment to follow the demoScript.txt:&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;1)  Copy DBGDesignLinks to the SharePoint server's  feature folder  (12\Template\Feature). This simple feature will add two links to the Site Actions menu to access the Features management page.&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;2)  Copy the code located in the Microsoft.PowerShell_profile.ps1  file to your profile.ps1 file. To locate your profile simply type in $profile at the PowerShell prompt.  The  Microsoft.PowerShell_profile.ps1 file  contains some basic functions such as AddFeatureToWeb,  RemoveFeatureToWeb  as well as loading the SharePoint assembly and creating  PSDrives. You will need to exit and restart PowerShell so PowerShell will load up the functions in the profile. &lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;3)  Copy the files located in the PSScripts folder to C:\ PSScripts.   These script files are used in the demoScript.txt file to Create and Delete sub webs. There is also txt file that contains the information about the sub webs that will be created.&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;&lt;br /&gt;
Once done,  you can copy the commands from the demo script to recreate the demo. The basic demo will:&lt;/font&gt;&lt;/p&gt;
&lt;ul&gt;
    &lt;li&gt;
    &lt;div&gt;Install a feature&lt;/div&gt;
    &lt;/li&gt;
    &lt;li&gt;
    &lt;div&gt;Create  sub sites from a configuration file&lt;/div&gt;
    &lt;/li&gt;
    &lt;li&gt;
    &lt;div&gt;Add the feature to the sub sites&lt;/div&gt;
    &lt;/li&gt;
    &lt;li&gt;
    &lt;div&gt;Find the sub sites with the feature&lt;/div&gt;
    &lt;/li&gt;
    &lt;li&gt;
    &lt;div&gt;Remove the feature from the sub site&lt;/div&gt;
    &lt;/li&gt;
    &lt;li&gt;
    &lt;div&gt;Delete the sites&lt;/div&gt;
    &lt;/li&gt;
    &lt;li&gt;
    &lt;div&gt;Uninstall the feature.&lt;br /&gt;
     &lt;/div&gt;
    &lt;/li&gt;
&lt;/ul&gt;
Check back soon for a few more simple but powerfull PowerShell functions and filters that can be easily chained togehter to provide basic access to key SharePoint objects.&lt;img src="http://darrinbishop.com/blog/aggbug/72.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Darrin Bishop</dc:creator>
            <guid>http://darrinbishop.com/blog/archive/2007/11/23/72.aspx</guid>
            <pubDate>Sat, 24 Nov 2007 02:18:06 GMT</pubDate>
            <comments>http://darrinbishop.com/blog/archive/2007/11/23/72.aspx#feedback</comments>
            <slash:comments>2</slash:comments>
            <wfw:commentRss>http://darrinbishop.com/blog/comments/commentRss/72.aspx</wfw:commentRss>
            <trackback:ping>http://darrinbishop.com/blog/services/trackbacks/72.aspx</trackback:ping>
        </item>
    </channel>
</rss>