I'm working on multi tenant provisioning in sharepoint and I'm having trouble figuring out if you can set the user account directory path for a site subscription using the sharepoint object model. I know this can be done through powershell with the following cmdlet.
$sub = New-SPSiteSubscription
$sub | Set-SPSiteSubscriptionConfig -UserAccountDirectoryPath "OU=AlpineBikeStore,OU=Hosting,DC=contoso,DC=com" -FeaturePack "50976ac2-83bb-4110-946d-95b4b6e90d42" -Confirm:$false
So far I've got the following code that will create a site subscription with a default site and feature pack. However, I can't figure out how to set the path to the users OU in active directory.
//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);
Any suggestions?
As Rikard suggested I used reflection for you.
Set-SPSiteSubscriptionConfig
does the following:
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();
}
As you can see it uses the GetAdminProperties
method to get the admin properties of the SPSiteSubscriptionManager
.
It then goes ahead and just updates the SPSiteSubscriptionProperty
inside the adminProperties collection with the value "UserAccountDirectoryPath"
.
All you need to do now is to set this as well and you're done. You can use a program such as ILSpy to look at the code of the SharePoint Powershell commandlets. In this case you could have found the code in Microsoft.SharePoint.PowerShell.SPCmdletSetSiteSubscriptionConfig
.