I need to update properties of several custom templates in my tenant. After reading the warning in Set-AadrmTemplateProperty (see excerpt below), I want to ensure that I have at least a last-known-good set of these templates.
Excerpt from article:
Important: When you update properties of a custom template, the existing settings for those properties will be overwritten (not supplemented) without warning, so be sure to specify all the settings that you need for the properties that you are updating.
As a best practice, back up the existing template before you run this cmdlet, by using the Export-AadrmTemplate cmdlet. Then, if you need to revert to the original configuration, you can use the Import-AadrmTemplate cmdlet to restore the template.
The Export-AadrmTemplate article provides an example of how to export (back up) one template. Well, I don’t want to do this (one at a time) for all the templates I have in my tenant. So, I wrote the following script to export all templates that I need.
$ShortDate = Get-Date -Format yyyyMMdd
$OutPath = “C:\Azure RMS\Backup\”
$OutFolder = New-Item -ItemType Directory -Force -Path $OutPath$ShortDate
Foreach ($Template in ($Templates = Get-AadrmTemplate))
$TemplateName = $Template.Names
$TemplateStatus = $Template.Status
If ($TemplateName -match “1033” -and $TemplateStatus -match “Published”)
$RMSTemplateFileName = ($TemplateName.Value.Substring(0) -replace ” “,“” -replace “\\”,“” -replace “-“,“”)
$OutFile = “$($OutFolder)\$($RMSTemplateFileName).xml”
Export-AadrmTemplate -TemplateId $Template.TemplateId -Path $OutFile -Force
Get-Variable | Remove-Variable -EA 0
Get-PSSession | Remove-PSSession
The script creates a new directory and writes the export files to it in case I need to run this frequently.
Obviously, the If statement and any of the variables can be changed to meet your needs.
This script works well for me.
Thanks for reading!