<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://www.dotnetmafia.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>Corey Roth [MVP] : Visual Studio 2010, SharePoint 2010, PowerShell</title><link>http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/tags/Visual+Studio+2010/SharePoint+2010/PowerShell/default.aspx</link><description>Tags: Visual Studio 2010, SharePoint 2010, PowerShell</description><dc:language>en</dc:language><generator>CommunityServer 2007.1 (Build: 20917.1142)</generator><item><title>How to: Debug a PowerShell Cmdlet</title><link>http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2010/09/09/how-to-debug-a-powershell-cmdlet.aspx</link><pubDate>Thu, 09 Sep 2010 15:40:29 GMT</pubDate><guid isPermaLink="false">ceb7fe2a-c56b-4d85-99e6-8dd548580538:3995</guid><dc:creator>CoreyRoth</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://www.dotnetmafia.com/blogs/dotnettipoftheday/rsscomments.aspx?PostID=3995</wfw:commentRss><comments>http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2010/09/09/how-to-debug-a-powershell-cmdlet.aspx#comments</comments><description>&lt;p&gt;In sticking with our theme of debugging things from &lt;a href="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2010/09/08/how-to-debug-a-custom-index-connector.aspx"&gt;yesterday&lt;/a&gt;, I thought I would write up a quick post on how to debug a cmdlet.&amp;#160; This may be obvious to you experienced developers out there, but someone new to writing cmdlets may not be familiar with the process.&amp;#160; Luckily, cmdlets are easier to debug than the Custom Index Connectors I talked about yesterday.&amp;#160; I hope to educate people as much as I can on &lt;a href="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2010/04/26/how-to-build-a-sharepoint-2010-powershell-cmdlet.aspx"&gt;how to build cmdlets&lt;/a&gt;, so that we can get more contributions to the &lt;a href="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2010/08/09/introducing-the-sharepoint-powershell-community-toolkit.aspx"&gt;SharePoint PowerShell Community Toolkit&lt;/a&gt;.&amp;#160; If you haven’t checked it out yet, please do. :-)&lt;/p&gt;  &lt;p&gt;Once you have built your cmdlet, set a breakpoint in your code in Visual Studio.&amp;#160; Once you have done that, open a new PowerShell window (or a SharePoint Management Shell) and install your module or snapin.&amp;#160; The technique for debugging is the same whether you load your cmdlet with Add-PSSnapin or Import-Module.&amp;#160; In Visual Studio, go to Debug –&amp;gt; Attach to Process.&amp;#160; Scroll through the list and look for &lt;em&gt;powershell.exe&lt;/em&gt;.&amp;#160; If you launched PowerShell using the SharePoint 2010 Management Shell icon you will notice the title in the list as shown below.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.dotnetmafia.com/blogs/dotnettipoftheday/PowerShellCmdletDebugAttachToProcess_60418FE8.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="PowerShellCmdletDebugAttachToProcess" border="0" alt="PowerShellCmdletDebugAttachToProcess" src="http://www.dotnetmafia.com/blogs/dotnettipoftheday/PowerShellCmdletDebugAttachToProcess_thumb_5EFCF709.png" width="503" height="343" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;When you find the right process, select it and click the attach button.&amp;#160; Now, go to your PowerShell window and run your command.&amp;#160; If all goes according to plan, your breakpoint will be hit and you can step through the code of your cmdlet.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.dotnetmafia.com/blogs/dotnettipoftheday/PowerShellCmdletDebug_36EA47EA.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="PowerShellCmdletDebug" border="0" alt="PowerShellCmdletDebug" src="http://www.dotnetmafia.com/blogs/dotnettipoftheday/PowerShellCmdletDebug_thumb_23C91B3E.png" width="520" height="288" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;That’s all there is to it.&amp;#160; Isn’t developing for PowerShell easy? The snippet of code you see above is actually from a new cmdlet I am releasing soon in the SharePoint PowerShell Community Toolkit that lets you test search queries from the command line.&amp;#160; I’ve already found it to be a handy cmdlet when I want to test a query using the API quickly. &lt;/p&gt;&lt;img src="http://www.dotnetmafia.com/aggbug.aspx?PostID=3995" width="1" height="1"&gt;</description><category domain="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/tags/SharePoint/default.aspx">SharePoint</category><category domain="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/tags/Debugging/default.aspx">Debugging</category><category domain="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/tags/Visual+Studio+2010/default.aspx">Visual Studio 2010</category><category domain="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/tags/SharePoint+2010/default.aspx">SharePoint 2010</category><category domain="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/tags/PowerShell/default.aspx">PowerShell</category></item></channel></rss>