Created
April 23, 2020 14:03
-
-
Save gautamdsheth/0a2afbf5328188f23023ab3fda3f947d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace ConsoleApp1 | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
AuthenticationManager authenticationManager = new AuthenticationManager(); | |
using (ClientContext clientContext = authenticationManager.GetSharePointOnlineAuthenticatedContextTenant("https://tenant-admin.sharepoint.com/", "userName", "password")) | |
{ | |
var tenant = new Tenant(clientContext); | |
ProvisioningHierarchy hierarchyToApply = LoadProvisioningHierarchyFromFile("C:\\PnP\\Templates\\TenantUserProfiletemplate.xml", null); | |
tenant.ApplyTenantTemplate(hierarchyToApply, "SAMPLE-SEQUENCE"); | |
} | |
} | |
public static ProvisioningHierarchy LoadProvisioningHierarchyFromFile(string templatePath, ITemplateProviderExtension[] templateProviderExtensions) | |
{ | |
// Prepare the File Connector | |
string templateFileName = System.IO.Path.GetFileName(templatePath); | |
// Prepare the template path | |
var fileInfo = new FileInfo(templatePath); | |
FileConnectorBase fileConnector = new FileSystemConnector(fileInfo.DirectoryName, ""); | |
// Load the provisioning template file | |
var isOpenOfficeFile = false; | |
XMLTemplateProvider provider; | |
if (isOpenOfficeFile) | |
{ | |
provider = new XMLOpenXMLTemplateProvider(new OpenXMLConnector(templateFileName, fileConnector)); | |
templateFileName = templateFileName.Substring(0, templateFileName.LastIndexOf(".", StringComparison.Ordinal)) + ".xml"; | |
var hierarchy = (provider as XMLOpenXMLTemplateProvider).GetHierarchy(); | |
if (hierarchy != null) | |
{ | |
hierarchy.Connector = provider.Connector; | |
return hierarchy; | |
} | |
} | |
else | |
{ | |
provider = new XMLFileSystemTemplateProvider(fileConnector.Parameters[FileConnectorBase.CONNECTIONSTRING] + "", ""); | |
} | |
ProvisioningHierarchy provisioningHierarchy = provider.GetHierarchy(templateFileName); | |
provisioningHierarchy.Connector = provider.Connector; | |
// Return the result | |
return provisioningHierarchy; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment