Search code examples
azurepowershellsharepointonedriveazure-runbook

How can I apply a SharePoint site template on an Azure PowerShell Runbook?


How would I apply a SharePoint site template, saved as an XML file in my One Drive, to a newly created site through a PowerShell Azure Runbook?

Currently, on my local machine, I use Apply-PnPProvisioningTemplate -Path "path to XML file" -ClearNavigation

I do not know where to store the XML file, or how to access it with a Runbook, thank you


Solution

  • You can store your xml file in the blob storage, then in azure runbook -> download the xml file from blob storage.

    The code in runbook like below:

    #download xml file from blob storage
    
     $account_name = "blob_storage_account_name"
     $account_key = "blob_storage_account_key"
    
    $context = New-AzStorageContext -StorageAccountName $account_name -StorageAccountKey $account_key
    
    $xml_name_local="your_xml_name_when_download_to_local"
    $blob_name = "your_xml"
    $container_name = "container_stored_xml_file"
    
    Get-AzStorageBlobContent -Blob $blob_name -Container $container_name -Destination "$Env:temp\$xml_name_local" -Context $context
    
    #then you can use "$Env:temp\$xml_name_local" to replace "path to XML file"
    
    Apply-PnPProvisioningTemplate -Path "path to XML file" -ClearNavigation