Setting up a sharepoint site signs a user account directory path using the object model

I’m working on providing multiple tenants in a sharepoint, and it’s hard for me to understand if you can set the path to the directory of the user account to subscribe to the site using the sharepoint object model. I know that this can be done through powershell using 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 have the following code that will create a subscription to the site with the site and the default feature pack. However, I cannot figure out how to set the path to the OU of users in the 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?

+7
source share
1 answer

As Rickard said, 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 SPSiteSubscriptionManager admin SPSiteSubscriptionManager . Then it goes ahead and simply updates the SPSiteSubscriptionProperty inside the adminProperties collection with the value "UserAccountDirectoryPath" .

All you have to do is install it and you're done. You can use a program such as ILSpy to look at the Powershell SharePoint cmdlet code. In this case, you could find the code in Microsoft.SharePoint.PowerShell.SPCmdletSetSiteSubscriptionConfig .

+1
source

All Articles