Get implementation of sharepoint powershell cmdlets

房东的猫 提交于 2020-01-07 03:47:46

问题


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?


回答1:


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

  1. How to import an SPWeb using c# to have the same behavior than PowerShell?


来源:https://stackoverflow.com/questions/44294577/get-implementation-of-sharepoint-powershell-cmdlets

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!