Nic*_*ula 7 sharepoint sharepoint-2010 sharepoint-object-model
我正在使用sharepoint进行多租户配置,而我无法确定是否可以使用sharepoint对象模型为站点订阅设置用户帐户目录路径.我知道这可以通过PowerShell使用以下cmdlet来完成.
$sub = New-SPSiteSubscription
$sub | Set-SPSiteSubscriptionConfig -UserAccountDirectoryPath "OU=AlpineBikeStore,OU=Hosting,DC=contoso,DC=com" -FeaturePack "50976ac2-83bb-4110-946d-95b4b6e90d42" -Confirm:$false
Run Code Online (Sandbox Code Playgroud)
到目前为止,我已经获得了以下代码,这些代码将使用默认网站和功能包创建网站订阅.但是,我无法弄清楚如何在活动目录中设置用户OU的路径.
//Create a default admin site for this tenant
var site = new SPSite("https://contoso.com/", userToken);
//Create the subscription and assign the default admin site to it.
var sub = SPSiteSubscription.Create();
sub.Add(site);
//Get the feature pack and assign it to the subscription
var featurePacks = SPSiteSubscriptionSettingsManager.Local.GetAllFeaturePacks();
var pack = featurePacks.SingleOrDefault(x => x.Id == Guid.Parse("50976ac2-83bb-4110-946d-95b4b6e90d42"));
SPSiteSubscriptionSettingsManager.Local.AssignFeaturePackToSiteSubscription(pack, sub);
Run Code Online (Sandbox Code Playgroud)
有什么建议?
正如 Rikard 建议的那样,我为你使用了反射。
Set-SPSiteSubscriptionConfig
执行以下操作:
if (this.m_UserAccountDirectoryPathSpecified)
{
SPSiteSubscriptionPropertyCollection adminProperties = this.m_SettingsManager.GetAdminProperties(this.m_ResolvedIdentity);
if (!string.IsNullOrEmpty(this.UserAccountDirectoryPath))
{
adminProperties.SetValue("UserAccountDirectoryPath", this.UserAccountDirectoryPath);
}
else
{
adminProperties.Remove("UserAccountDirectoryPath");
}
adminProperties.Update();
}
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,它使用该GetAdminProperties
方法来获取SPSiteSubscriptionManager
. 然后它继续使用SPSiteSubscriptionProperty
value 更新 adminProperties 集合内部"UserAccountDirectoryPath"
。
您现在需要做的就是设置它,然后就完成了。您可以使用ILSpy等程序来查看 SharePoint Powershell commandlet 的代码。在这种情况下,您可以在 中找到代码 Microsoft.SharePoint.PowerShell.SPCmdletSetSiteSubscriptionConfig
。
归档时间: |
|
查看次数: |
1837 次 |
最近记录: |