<?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>John W Powell : PowerShell</title><link>http://blogs.msdn.com/johnwpowell/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>How to Copy an Assembly From the GAC to the File System</title><link>http://blogs.msdn.com/johnwpowell/archive/2009/01/14/how-to-copy-an-assembly-from-the-gac.aspx</link><pubDate>Wed, 14 Jan 2009 04:20:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9317728</guid><dc:creator>johnwpowell</dc:creator><slash:comments>8</slash:comments><comments>http://blogs.msdn.com/johnwpowell/comments/9317728.aspx</comments><wfw:commentRss>http://blogs.msdn.com/johnwpowell/commentrss.aspx?PostID=9317728</wfw:commentRss><description>&lt;P&gt;Sometimes you need a local copy of an assembly from the GAC and here is a quick tip on how to do it.&amp;nbsp; The GAC can be found in the c:\windows\assembly directory, but if you try to browse it, the following custom shell extension appears:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/johnwpowell/WindowsLiveWriter/HowtoCopyanAssemblyFromtheGAC_117F8/image_2.png" target=_blank mce_href="http://blogs.msdn.com/blogfiles/johnwpowell/WindowsLiveWriter/HowtoCopyanAssemblyFromtheGAC_117F8/image_2.png"&gt;&lt;IMG height=462 alt=image src="http://blogs.msdn.com/blogfiles/johnwpowell/WindowsLiveWriter/HowtoCopyanAssemblyFromtheGAC_117F8/image_thumb.png" width=616 border=0 mce_src="http://blogs.msdn.com/blogfiles/johnwpowell/WindowsLiveWriter/HowtoCopyanAssemblyFromtheGAC_117F8/image_thumb.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;This view does not provide the ability to copy assemblies, but it does provide some very useful information such as the strong name details.&amp;nbsp; Here are some options to get around that feature to copy an assembly from the GAC.&lt;/P&gt;
&lt;H3&gt;Option 1: Disable the Shell Extension in the Registry&lt;/H3&gt;
&lt;P&gt;One possibility, but not the best one, is to disable the shell extension.&amp;nbsp; I don't like this approach because it involves editing the registry and I like the information provided by the shell extension.&amp;nbsp; Here's how to disable the extension if you want to.&amp;nbsp; Open the registry editor and add/set the HKLM\Software\Microsoft\Fusion\DisableCacheViewer DWORD value:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/johnwpowell/WindowsLiveWriter/HowtoCopyanAssemblyFromtheGAC_117F8/image_4.png" target=_blank mce_href="http://blogs.msdn.com/blogfiles/johnwpowell/WindowsLiveWriter/HowtoCopyanAssemblyFromtheGAC_117F8/image_4.png"&gt;&lt;IMG height=137 alt=image src="http://blogs.msdn.com/blogfiles/johnwpowell/WindowsLiveWriter/HowtoCopyanAssemblyFromtheGAC_117F8/image_thumb_1.png" width=616 border=0 mce_src="http://blogs.msdn.com/blogfiles/johnwpowell/WindowsLiveWriter/HowtoCopyanAssemblyFromtheGAC_117F8/image_thumb_1.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;Set the value to 1:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/johnwpowell/WindowsLiveWriter/HowtoCopyanAssemblyFromtheGAC_117F8/image_6.png" target=_blank mce_href="http://blogs.msdn.com/blogfiles/johnwpowell/WindowsLiveWriter/HowtoCopyanAssemblyFromtheGAC_117F8/image_6.png"&gt;&lt;IMG height=192 alt=image src="http://blogs.msdn.com/blogfiles/johnwpowell/WindowsLiveWriter/HowtoCopyanAssemblyFromtheGAC_117F8/image_thumb_2.png" width=324 border=0 mce_src="http://blogs.msdn.com/blogfiles/johnwpowell/WindowsLiveWriter/HowtoCopyanAssemblyFromtheGAC_117F8/image_thumb_2.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;Once you make that change, you can browse the directory:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/johnwpowell/WindowsLiveWriter/HowtoCopyanAssemblyFromtheGAC_117F8/image_8.png" target=_blank mce_href="http://blogs.msdn.com/blogfiles/johnwpowell/WindowsLiveWriter/HowtoCopyanAssemblyFromtheGAC_117F8/image_8.png"&gt;&lt;IMG height=231 alt=image src="http://blogs.msdn.com/blogfiles/johnwpowell/WindowsLiveWriter/HowtoCopyanAssemblyFromtheGAC_117F8/image_thumb_3.png" width=616 border=0 mce_src="http://blogs.msdn.com/blogfiles/johnwpowell/WindowsLiveWriter/HowtoCopyanAssemblyFromtheGAC_117F8/image_thumb_3.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;H3&gt;Option 2: Go Command-O&lt;/H3&gt;
&lt;P&gt;Another option is to copy assemblies from the GAC from the command line.&amp;nbsp; This approach works well if you prefer working from the command line, but if you like to right-click with a mouse, this might not be the choice for you. &lt;/P&gt;
&lt;P&gt;I highly recommend PowerShell, but you can use Windows Command Prompt.&amp;nbsp; Find your way to the c:\windows\assembly directory and copy the file you need:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/johnwpowell/WindowsLiveWriter/HowtoCopyanAssemblyFromtheGAC_117F8/image_10.png" target=_blank mce_href="http://blogs.msdn.com/blogfiles/johnwpowell/WindowsLiveWriter/HowtoCopyanAssemblyFromtheGAC_117F8/image_10.png"&gt;&lt;IMG height=141 alt=image src="http://blogs.msdn.com/blogfiles/johnwpowell/WindowsLiveWriter/HowtoCopyanAssemblyFromtheGAC_117F8/image_thumb_4.png" width=640 border=0 mce_src="http://blogs.msdn.com/blogfiles/johnwpowell/WindowsLiveWriter/HowtoCopyanAssemblyFromtheGAC_117F8/image_thumb_4.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;H3&gt;Option 3: Use the SUBST Command&lt;/H3&gt;
&lt;P&gt;The SUBST command allows you to create a shortcut to a path on your file system and assigns that shortcut a drive letter.&amp;nbsp; I really like this approach because you have the option of using Windows Explorer without having to disable the shell.&lt;/P&gt;
&lt;P&gt;Suppose you want to create a G Drive (G for GAC), use the following command: SUBST G: C:\WINDOWS\ASSEMBLY&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/johnwpowell/WindowsLiveWriter/HowtoCopyanAssemblyFromtheGAC_117F8/image_12.png" target=_blank mce_href="http://blogs.msdn.com/blogfiles/johnwpowell/WindowsLiveWriter/HowtoCopyanAssemblyFromtheGAC_117F8/image_12.png"&gt;&lt;IMG height=53 alt=image src="http://blogs.msdn.com/blogfiles/johnwpowell/WindowsLiveWriter/HowtoCopyanAssemblyFromtheGAC_117F8/image_thumb_5.png" width=640 border=0 mce_src="http://blogs.msdn.com/blogfiles/johnwpowell/WindowsLiveWriter/HowtoCopyanAssemblyFromtheGAC_117F8/image_thumb_5.png"&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Then in Windows Explorer you are free to double-click and right-click to your heart's content and still use the shell extension.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/johnwpowell/WindowsLiveWriter/HowtoCopyanAssemblyFromtheGAC_117F8/image_14.png" target=_blank mce_href="http://blogs.msdn.com/blogfiles/johnwpowell/WindowsLiveWriter/HowtoCopyanAssemblyFromtheGAC_117F8/image_14.png"&gt;&lt;IMG height=277 alt=image src="http://blogs.msdn.com/blogfiles/johnwpowell/WindowsLiveWriter/HowtoCopyanAssemblyFromtheGAC_117F8/image_thumb_6.png" width=616 border=0 mce_src="http://blogs.msdn.com/blogfiles/johnwpowell/WindowsLiveWriter/HowtoCopyanAssemblyFromtheGAC_117F8/image_thumb_6.png"&gt;&lt;/A&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9317728" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/johnwpowell/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://blogs.msdn.com/johnwpowell/archive/tags/.Net/default.aspx">.Net</category><category domain="http://blogs.msdn.com/johnwpowell/archive/tags/SharePoint/default.aspx">SharePoint</category><category domain="http://blogs.msdn.com/johnwpowell/archive/tags/PowerShell/default.aspx">PowerShell</category></item><item><title>Build PowerShell CmdLets to call SharePoint Web Services using WCF</title><link>http://blogs.msdn.com/johnwpowell/archive/2008/11/02/build-powershell-cmdlets-to-call-sharepoint-web-services-using-wcf.aspx</link><pubDate>Mon, 03 Nov 2008 00:22:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9029678</guid><dc:creator>johnwpowell</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/johnwpowell/comments/9029678.aspx</comments><wfw:commentRss>http://blogs.msdn.com/johnwpowell/commentrss.aspx?PostID=9029678</wfw:commentRss><description>&lt;P&gt;In this post I'll show you how to build a PowerShell cmdlet that consumes SharePoint web services using WCF.&amp;nbsp; What I like about this approach is that it provides the ability to use &lt;EM&gt;some&lt;/EM&gt; of the SharePoint API without having to be logged in to the SharePoint server.&amp;nbsp; Although you can accomplish the same thing using PowerShell scripts and functions, in this post we'll build a SharePoint cmdlet using C#.&amp;nbsp; &lt;/P&gt;
&lt;H3&gt;About the Approach&lt;/H3&gt;
&lt;P&gt;There are several advantages of combining PowerShell and SharePoint web services:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Consume the SharePoint API without logging on to a SharePoint server 
&lt;LI&gt;Provide a layer of abstraction and reusable task-oriented building blocks 
&lt;LI&gt;Reduce risk of performance issues caused by PowerShell scripts that don't dispose of unmanaged SharePoint resources&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;There are also some drawbacks to writing custom cmdlets that consume SharePoint web services:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;SharePoint web services do not expose the full API; you may need to augment them with business-specific functionality 
&lt;LI&gt;Cmdlets require compilation and additional overhead over script file&lt;/LI&gt;&lt;/UL&gt;
&lt;H3&gt;Getting Started&lt;/H3&gt;
&lt;P&gt;In this walkthrough, I'm using Visual Studio 2008 on a SharePoint virtual machine.&amp;nbsp; Although you &lt;EM&gt;could&lt;/EM&gt; use a Visual Studio PowerShell project template, we'll are going to build everything by hand so there are no mysteries.&amp;nbsp; So let's get started by creating a new class library project:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/johnwpowell/WindowsLiveWriter/d480dd7087aa_8548/image_2.png" target=_blank mce_href="http://blogs.msdn.com/blogfiles/johnwpowell/WindowsLiveWriter/d480dd7087aa_8548/image_2.png"&gt;&lt;IMG height=163 alt=image src="http://blogs.msdn.com/blogfiles/johnwpowell/WindowsLiveWriter/d480dd7087aa_8548/image_thumb.png" width=240 border=0 mce_src="http://blogs.msdn.com/blogfiles/johnwpowell/WindowsLiveWriter/d480dd7087aa_8548/image_thumb.png"&gt;&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Add a reference to PowerShell which is contained in System.Management.Automation assembly.&amp;nbsp; If you've installed the Windows SDK, you can find it in the following location: C:\Program Files\Reference Assemblies\Microsoft\WindowsPowerShell\v1.0&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/johnwpowell/WindowsLiveWriter/d480dd7087aa_8548/image3.png" target=_blank mce_href="http://blogs.msdn.com/blogfiles/johnwpowell/WindowsLiveWriter/d480dd7087aa_8548/image3.png"&gt;&lt;IMG height=197 alt=image src="http://blogs.msdn.com/blogfiles/johnwpowell/WindowsLiveWriter/d480dd7087aa_8548/image3_thumb.png" width=240 border=0 mce_src="http://blogs.msdn.com/blogfiles/johnwpowell/WindowsLiveWriter/d480dd7087aa_8548/image3_thumb.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;Since we are creating a class that will both describe and install a custom snap in, we need to reference System.Configuration.Install&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/johnwpowell/WindowsLiveWriter/d480dd7087aa_8548/image9.png" target=_blank mce_href="http://blogs.msdn.com/blogfiles/johnwpowell/WindowsLiveWriter/d480dd7087aa_8548/image9.png"&gt;&lt;IMG height=197 alt=image src="http://blogs.msdn.com/blogfiles/johnwpowell/WindowsLiveWriter/d480dd7087aa_8548/image9_thumb.png" width=240 border=0 mce_src="http://blogs.msdn.com/blogfiles/johnwpowell/WindowsLiveWriter/d480dd7087aa_8548/image9_thumb.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;H3&gt;Create the Snap In and Cmdlet&lt;/H3&gt;
&lt;P&gt;Add a new class that inherits CustomPSSnapIn.&amp;nbsp; Add the RunInstaller attribute to the class and describe the snap in by overriding the Name, Vendor and Description properties.&amp;nbsp; Your code should end up looking like this:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/johnwpowell/WindowsLiveWriter/d480dd7087aa_8548/image12.png" target=_blank mce_href="http://blogs.msdn.com/blogfiles/johnwpowell/WindowsLiveWriter/d480dd7087aa_8548/image12.png"&gt;&lt;IMG height=783 alt=image src="http://blogs.msdn.com/blogfiles/johnwpowell/WindowsLiveWriter/d480dd7087aa_8548/image12_thumb.png" width=515 border=0 mce_src="http://blogs.msdn.com/blogfiles/johnwpowell/WindowsLiveWriter/d480dd7087aa_8548/image12_thumb.png"&gt;&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Add a new class that inherits from Cmdlet.&amp;nbsp; We'll build a cmdlet to get information about a SharePoint site, so name it "GetSPWebCmdlet."&amp;nbsp; Add the Cmdlet attribute to the class. You'll notice the cmdlet name, "Get-SPWeb" is a combination of the noun string &lt;EM&gt;SPWeb&lt;/EM&gt; and verb enumeration &lt;EM&gt;VerbsCommon.Get&lt;/EM&gt; specified by the Cmdlet attribute:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/johnwpowell/WindowsLiveWriter/d480dd7087aa_8548/image18.png" target=_blank mce_href="http://blogs.msdn.com/blogfiles/johnwpowell/WindowsLiveWriter/d480dd7087aa_8548/image18.png"&gt;&lt;IMG height=289 alt=image src="http://blogs.msdn.com/blogfiles/johnwpowell/WindowsLiveWriter/d480dd7087aa_8548/image18_thumb.png" width=386 border=0 mce_src="http://blogs.msdn.com/blogfiles/johnwpowell/WindowsLiveWriter/d480dd7087aa_8548/image18_thumb.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;Override the Cmdlets property in the snap in class and add the Get-SPWeb cmdlet to the Cmdlets collection:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/johnwpowell/WindowsLiveWriter/d480dd7087aa_8548/image21.png" target=_blank mce_href="http://blogs.msdn.com/blogfiles/johnwpowell/WindowsLiveWriter/d480dd7087aa_8548/image21.png"&gt;&lt;IMG height=231 alt=image src="http://blogs.msdn.com/blogfiles/johnwpowell/WindowsLiveWriter/d480dd7087aa_8548/image21_thumb.png" width=805 border=0 mce_src="http://blogs.msdn.com/blogfiles/johnwpowell/WindowsLiveWriter/d480dd7087aa_8548/image21_thumb.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;H3&gt;Configure Visual Studio to Install and Add the Snap In When the Project is Debugged&lt;/H3&gt;
&lt;P&gt;Before we add any code to the cmdlet, let's configure Visual Studio to automatically deploy the snap in to make debugging easier.&amp;nbsp; We'll use a post-build event to install the snap in, so in the spirit of learning PowerShell, we'll write the post-build script in PowerShell!&amp;nbsp; Add a new text file to your project named PostBuildEvent.ps1.&amp;nbsp; Add the following script to the file:&lt;/P&gt;
&lt;P&gt;trap &lt;BR&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp; $errorTxt = $_.Exception.Message&lt;BR&gt;&amp;nbsp;&amp;nbsp; write-output "$errorTxt"&lt;BR&gt;&amp;nbsp;&amp;nbsp; break&lt;BR&gt;} 
&lt;P&gt;$targetDir = $args[0]&lt;BR&gt;$targetFileName = $args[1]&lt;BR&gt;$snapInName = $args[2] 
&lt;P&gt;write-output "Deploying..."&lt;BR&gt;join-path $targetDir $targetFileName&lt;BR&gt;write-output "Snap In Name: $snapInName" 
&lt;P&gt;set-location $targetDir&lt;BR&gt;set-alias installutil $env:windir\Microsoft.NET\Framework\v2.0.50727\installutil&lt;BR&gt;installutil $targetFileName 
&lt;P&gt;Notice the script file takes some arguments (targetDir, targetFileName and snapInName).&amp;nbsp; Using that information, it installs the SnapIn (and our SharePoint cmdlet).&amp;nbsp; Configure Visual Studio to pass the arguments to the post-build event:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/johnwpowell/WindowsLiveWriter/d480dd7087aa_8548/image27.png" target=_blank mce_href="http://blogs.msdn.com/blogfiles/johnwpowell/WindowsLiveWriter/d480dd7087aa_8548/image27.png"&gt;&lt;IMG height=235 alt=image src="http://blogs.msdn.com/blogfiles/johnwpowell/WindowsLiveWriter/d480dd7087aa_8548/image27_thumb.png" width=422 border=0 mce_src="http://blogs.msdn.com/blogfiles/johnwpowell/WindowsLiveWriter/d480dd7087aa_8548/image27_thumb.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;After a SnapIn is installed, you have to add it to your environment before it can be used.&amp;nbsp; As you can see, even though our custom snap in has been installed, it is not listed when you call &lt;EM&gt;Get-PSSnapin&lt;/EM&gt;:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/johnwpowell/WindowsLiveWriter/d480dd7087aa_8548/image_20.png" target=_blank mce_href="http://blogs.msdn.com/blogfiles/johnwpowell/WindowsLiveWriter/d480dd7087aa_8548/image_20.png"&gt;&lt;IMG height=212 alt=image src="http://blogs.msdn.com/blogfiles/johnwpowell/WindowsLiveWriter/d480dd7087aa_8548/image_thumb_7.png" width=640 border=0 mce_src="http://blogs.msdn.com/blogfiles/johnwpowell/WindowsLiveWriter/d480dd7087aa_8548/image_thumb_7.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;To add it, call &lt;EM&gt;Add-PSSnapin&lt;/EM&gt; passing in the name of the assembly:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/johnwpowell/WindowsLiveWriter/d480dd7087aa_8548/image_22.png" target=_blank mce_href="http://blogs.msdn.com/blogfiles/johnwpowell/WindowsLiveWriter/d480dd7087aa_8548/image_22.png"&gt;&lt;IMG height=158 alt=image src="http://blogs.msdn.com/blogfiles/johnwpowell/WindowsLiveWriter/d480dd7087aa_8548/image_thumb_9.png" width=640 border=0 mce_src="http://blogs.msdn.com/blogfiles/johnwpowell/WindowsLiveWriter/d480dd7087aa_8548/image_thumb_9.png"&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;We don't want to add the snap in after each code change, so we are going to automate it by adding a console file that will add the snap in into our environment when the project is debugged.&amp;nbsp; Add a new file named SharePointSamples.Console.psc1 to your project.&amp;nbsp; Put the following xml in the file:&lt;/P&gt;
&lt;P&gt;&amp;lt;?xml version="1.0" encoding="utf-8"?&amp;gt;&lt;BR&gt;&amp;lt;PSConsoleFile ConsoleSchemaVersion="1.0"&amp;gt;&lt;BR&gt;&amp;nbsp; &amp;lt;PSVersion&amp;gt;1.0&amp;lt;/PSVersion&amp;gt;&lt;BR&gt;&amp;nbsp; &amp;lt;PSSnapIns&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;PSSnapIn Name="SharePointSamples.PowerShell" /&amp;gt;&lt;BR&gt;&amp;nbsp; &amp;lt;/PSSnapIns&amp;gt;&lt;BR&gt;&amp;lt;/PSConsoleFile&amp;gt; 
&lt;P&gt;In the project configuration, Debug settings, configure Visual Studio to start PowerShell when you debug and in the command-line arguments section, use the -PSConsoleFile argument to specify the console file you created:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/johnwpowell/WindowsLiveWriter/d480dd7087aa_8548/image_16.png" target=_blank mce_href="http://blogs.msdn.com/blogfiles/johnwpowell/WindowsLiveWriter/d480dd7087aa_8548/image_16.png"&gt;&lt;IMG height=316 alt=image src="http://blogs.msdn.com/blogfiles/johnwpowell/WindowsLiveWriter/d480dd7087aa_8548/image_thumb_2.png" width=499 border=0 mce_src="http://blogs.msdn.com/blogfiles/johnwpowell/WindowsLiveWriter/d480dd7087aa_8548/image_thumb_2.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;H3&gt;Implement the Cmdlet&lt;/H3&gt;
&lt;P&gt;Now that deployment and debugging are taken care of, add the following code to the cmdlet:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;A href="http://blogs.msdn.com/blogfiles/johnwpowell/WindowsLiveWriter/d480dd7087aa_8548/image_24.png" target=_blank mce_href="http://blogs.msdn.com/blogfiles/johnwpowell/WindowsLiveWriter/d480dd7087aa_8548/image_24.png"&gt;&lt;IMG height=568 alt=image src="http://blogs.msdn.com/blogfiles/johnwpowell/WindowsLiveWriter/d480dd7087aa_8548/image_thumb_10.png" width=711 border=0 mce_src="http://blogs.msdn.com/blogfiles/johnwpowell/WindowsLiveWriter/d480dd7087aa_8548/image_thumb_10.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;The cmdlet takes the url of the site as an argument.&amp;nbsp; Arguments are implemented as class properties decorated with the &lt;EM&gt;Parameter&lt;/EM&gt; attribute.&amp;nbsp; The work is implemented in the &lt;EM&gt;ProcessRecord&lt;/EM&gt; method.&amp;nbsp; As you can see, I already did some re-factoring and created a service locator class that will give me an instance of the SharePoint &lt;EM&gt;Webs&lt;/EM&gt; service (using WCF).&amp;nbsp; The code then invokes the &lt;EM&gt;GetWeb&lt;/EM&gt; method and writes out the resulting xml.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;Here is the code for the service locator.&amp;nbsp; As you can see it configures the SharePoint Webs proxy: &lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/johnwpowell/WindowsLiveWriter/d480dd7087aa_8548/image_28.png" target=_blank mce_href="http://blogs.msdn.com/blogfiles/johnwpowell/WindowsLiveWriter/d480dd7087aa_8548/image_28.png"&gt;&lt;IMG height=324 alt=image src="http://blogs.msdn.com/blogfiles/johnwpowell/WindowsLiveWriter/d480dd7087aa_8548/image_thumb_12.png" width=640 border=0 mce_src="http://blogs.msdn.com/blogfiles/johnwpowell/WindowsLiveWriter/d480dd7087aa_8548/image_thumb_12.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;Most of the key WCF configuration settings for integrated authentication are implemented in the BindingFactory class:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/johnwpowell/WindowsLiveWriter/d480dd7087aa_8548/image_30.png" target=_blank mce_href="http://blogs.msdn.com/blogfiles/johnwpowell/WindowsLiveWriter/d480dd7087aa_8548/image_30.png"&gt;&lt;IMG height=311 alt=image src="http://blogs.msdn.com/blogfiles/johnwpowell/WindowsLiveWriter/d480dd7087aa_8548/image_thumb_13.png" width=640 border=0 mce_src="http://blogs.msdn.com/blogfiles/johnwpowell/WindowsLiveWriter/d480dd7087aa_8548/image_thumb_13.png"&gt;&lt;/A&gt;&lt;/P&gt;
&lt;H3&gt;Test the Cmdlet&lt;/H3&gt;
&lt;P&gt;To test the cmdlet, run the project.&amp;nbsp; When the PowerShell command prompt opens, type &lt;EM&gt;Get-SPWeb&lt;/EM&gt;.&amp;nbsp; You will be prompted for the site url if you don't provide it:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/johnwpowell/WindowsLiveWriter/d480dd7087aa_8548/image_26.png" target=_blank mce_href="http://blogs.msdn.com/blogfiles/johnwpowell/WindowsLiveWriter/d480dd7087aa_8548/image_26.png"&gt;&lt;IMG height=217 alt=image src="http://blogs.msdn.com/blogfiles/johnwpowell/WindowsLiveWriter/d480dd7087aa_8548/image_thumb_11.png" width=505 border=0 mce_src="http://blogs.msdn.com/blogfiles/johnwpowell/WindowsLiveWriter/d480dd7087aa_8548/image_thumb_11.png"&gt;&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;H3&gt;Summary&lt;/H3&gt;
&lt;P&gt;In this walkthrough, you learned how to leverage PowerShell, WCF and the SharePoint web services to implement a custom cmdlet.&amp;nbsp; Using this approach, you can expand the administrative capabilities of SharePoint and build reusable, task-oriented building blocks to increase your productivity and capability.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://cid-7cedcb8ed3a44629.skydrive.live.com/self.aspx/Public/SharePointSamples.zip" target=_blank mce_href="http://cid-7cedcb8ed3a44629.skydrive.live.com/self.aspx/Public/SharePointSamples.zip"&gt;Get the code&lt;/A&gt; for this article.&lt;/P&gt;
&lt;H3&gt;Additional Reading&lt;/H3&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;A href="http://www.capdes.com/2007/03/visual_studio_post_build_event.html" target=_blank mce_href="http://www.capdes.com/2007/03/visual_studio_post_build_event.html"&gt;Visual Studio Build Events With PowerShell&lt;/A&gt; 
&lt;LI&gt;&lt;A href="http://www.wrox.com/WileyCDA/Section/id-320555.html" target=_blank mce_href="http://www.wrox.com/WileyCDA/Section/id-320555.html"&gt;Extending Windows Powershell with Snap-ins&lt;/A&gt; 
&lt;LI&gt;&lt;A href="http://sharepoint.microsoft.com/blogs/zach/Lists/Posts/Post.aspx?List=90bbfd11-c9a5-45cf-a77e-19559aae81ae&amp;amp;ID=7" target=_blank mce_href="http://sharepoint.microsoft.com/blogs/zach/Lists/Posts/Post.aspx?List=90bbfd11-c9a5-45cf-a77e-19559aae81ae&amp;amp;ID=7"&gt;Managing SharePoint with PowerShell&lt;/A&gt; 
&lt;LI&gt;&lt;A href="http://cglessner.blogspot.com/2008/06/powershell-sharepoint.html" target=_blank mce_href="http://cglessner.blogspot.com/2008/06/powershell-sharepoint.html"&gt;PowerShell &amp;amp; SharePoint - Quick Start&lt;/A&gt; 
&lt;LI&gt;&lt;A href="http://darrinbishop.com/blog/archive/2007/04/08/54.aspx" target=_blank mce_href="http://darrinbishop.com/blog/archive/2007/04/08/54.aspx"&gt;SharePoint and PowerShell Demo&lt;/A&gt; 
&lt;LI&gt;&lt;A href="http://www.trentswanson.com/post/2008/01/Calling-SharePoint-web-services-using-Visual-Studio-20082c-WCF2c-and-Windows-Auth.aspx" target=_blank mce_href="http://www.trentswanson.com/post/2008/01/Calling-SharePoint-web-services-using-Visual-Studio-20082c-WCF2c-and-Windows-Auth.aspx"&gt;Calling SharePoint web services using Visual Studio 2008, WCF, and Windows Authentication&lt;/A&gt; 
&lt;LI&gt;&lt;A href="http://darrinbishop.com/blog/archive/2007/11/28/psfivefunctions.aspx" target=_blank mce_href="http://darrinbishop.com/blog/archive/2007/11/28/psfivefunctions.aspx"&gt;Five Simple But Powerful PowerShell Functions/Filters for SharePoint&lt;/A&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9029678" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/johnwpowell/archive/tags/Windows+SharePoint+Services/default.aspx">Windows SharePoint Services</category><category domain="http://blogs.msdn.com/johnwpowell/archive/tags/SharePoint+2007/default.aspx">SharePoint 2007</category><category domain="http://blogs.msdn.com/johnwpowell/archive/tags/Windows+Communication+Foundation/default.aspx">Windows Communication Foundation</category><category domain="http://blogs.msdn.com/johnwpowell/archive/tags/WCF/default.aspx">WCF</category><category domain="http://blogs.msdn.com/johnwpowell/archive/tags/PowerShell/default.aspx">PowerShell</category></item></channel></rss>