Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gautamdsheth/0a2afbf5328188f23023ab3fda3f947d to your computer and use it in GitHub Desktop.
Save gautamdsheth/0a2afbf5328188f23023ab3fda3f947d to your computer and use it in GitHub Desktop.
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