$ErrorActionPreference = "Stop" $resourcegrouptoexport = "lnd-demo-rg" $storageRG = "lnd-demo-rg" $StorageAccountName = "lndmigration" $filesharename = "rgconfbackup" $filename = Get-Date -format "--ddMMyyyy-HHmm" $filename = $resourcegrouptoexport + $filename + ".json" $path = "C:\temp\" + $filename $exportpath = "c:\temp" ##### Connect to Azure subscription $connectionName = "AzureRunAsConnection" try { # Get the connection "AzureRunAsConnection " $servicePrincipalConnection=Get-AutomationConnection -Name $connectionName "Logging in to Azure..." Add-AzureRmAccount ` -ServicePrincipal ` -TenantId $servicePrincipalConnection.TenantId ` -ApplicationId $servicePrincipalConnection.ApplicationId ` -CertificateThumbprint $servicePrincipalConnection.CertificateThumbprint } catch { if (!$servicePrincipalConnection) { $ErrorMessage = "Connection $connectionName not found." throw $ErrorMessage } else{ Write-Error -Message $_.Exception throw $_.Exception EXIT } } "Logging in to Azure okey..." ##### "Exporting RG" Export-AzureRmResourceGroup -ResourceGroupName $resourcegrouptoexport -Path $path "Exporting RG ok" ##### Upload RG JSON file to file share "Connecting to file share..." $key = (Get-AzureRmStorageAccountKey -ResourceGroupName $storageRG -AccountName $StorageAccountName).Value[0] $ctx = New-AzureStorageContext $StorageAccountName $key $fileshare = Get-AzureSTorageShare -Name $filesharename -Context $ctx "Uploading file to file share" Set-AzureStorageFileContent -Share $fileshare -Source $path -Path templates "All done :)"