How to find managed code SharePoint (whichever version) cmdlets implementations?
MSDN does not specify where and how cmdlets are implemented. There is only information how to use them. Is this done for some reason?
So I started digging…
Let’s for example take SharePoint 2013 15 Hive.
15 Hive
folder structure explained: SharePoint 2013: The 15 Hive and other important directories
CMDLET Registration files location
15/Config/Powershell/Registration
folder contains XML cmdlet registration files where for given assembly there are defined list of cmdlet definitions.
Sample XML
<ps:Cmdlet>
<ps:VerbName>Uninstall-SPFeature</ps:VerbName>
<ps:ClassName>Microsoft.SharePoint.PowerShell.SPCmdletUninstallFeature</ps:ClassName>
<ps:HelpFile>Microsoft.SharePoint.PowerShell.dll-help.xml</ps:HelpFile>
</ps:Cmdlet>
SharePoint cmdlets are registered in WSSCmdlet.xml (there is a lot more) and their definition Assembly is:
Assembly Name="Microsoft.SharePoint.PowerShell, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"
Assembly is located in GAC:
C:\Windows\Microsoft.NET\assembly\GAC_MSIL\Microsoft.SharePoint.PowerShell
Manged C# Code
Using decompiler like ILSpy you can find exact class in DLL and get c# implementation of cmdlet.
For example
[SPCmdlet(RequireLocalFarmExist = true), Cmdlet("Get", "SPSiteUrl", SupportsShouldProcess = true)]
public sealed class SPCmdletGetSPSiteUrl : SPGetCmdletBase<SPSiteUrl>
{
// implementation details irrelevant for question context
}
The Tricks