Created
March 4, 2019 20:20
-
-
Save garrytrinder/a64166dfe5056f0677499db1f7a742fa to your computer and use it in GitHub Desktop.
This file contains hidden or 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
Param( | |
[Parameter(Mandatory=$true)] | |
[string]$CredentialName, | |
[Parameter(Mandatory=$true)] | |
[string]$SiteUrl, | |
[Parameter(Mandatory=$true)] | |
[string]$TemplateName, | |
[Parameter(Mandatory=$true)] | |
[string]$StorageAccountName, | |
[Parameter(Mandatory=$true)] | |
[string]$StorageAccountResourceGroupName, | |
[Parameter(Mandatory=$true)] | |
[string]$StorageContainerName | |
) | |
$ErrorActionPreference = "Stop" | |
# connect to Azure using credential provided | |
Login-AzureRmAccount -Credential (Get-AutomationPSCredential -Name $CredentialName) | |
# get the key to access the Storage Account | |
$keys = Get-AzureRmStorageAccountKey -ResourceGroupName $StorageAccountResourceGroupName -Name $StorageAccountName | |
# get Azure Storage Account context | |
$context = New-AzureStorageContext -StorageAccountName $StorageAccountName -StorageAccountKey $keys.Key1 | |
# get a list of all the files in the container | |
$blobs = Get-AzureStorageBlob -Container $StorageContainerName -Context $context | |
# download all blobs locally | |
$blobs | ForEach-Object { | |
Get-AzureStorageBlobContent -Blob $_.Name -Destination "$home\$($_.Name)" -Context $context -Container $StorageContainerName | |
} | |
# create connection to SharePoint site | |
Connect-PnPOnline -Url $SiteUrl -Credentials (Get-AutomationPSCredential -Name $CredentialName) | |
# apply template | |
Apply-PnPProvisioningTemplate -Path "$home\$TemplateName" | |
# clean up SharePoint connection | |
Disconnect-PnPOnline |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment