조건부 액세스 정책 Backup/Restore 방법 안내해 드립니다. 

 

Azure AD 모듈 설치 방법은 아래의 링크를 참고하시기 바랍니다.

Graph용 AzureAD PowerShell 설치 | Microsoft Learn

 

Graph용 AzureAD PowerShell 설치

Azure AD PowerShell 모듈의 설치 프로세스에 대한 가이드를 제공합니다.

learn.microsoft.com

 

[조건부 액세스 백업]

1. PowerShell 관리자 권한으로 실행합니다.

2. 아래의 명령어를 입력하여 조건부 액세스 정책을 Backup을 진행합니다.

param(
    [parameter()]
    [String]$BackupPath
)
# Connect to Azure AD
Connect-AzureAD
 
$AllPolicies = Get-AzureADMSConditionalAccessPolicy
 
foreach ($Policy in $AllPolicies) {
    Write-Output "Backing up $($Policy.DisplayName)"
    $PolicyJSON = $Policy | ConvertTo-Json -Depth 6
    $PolicyJSON | Out-File "$BackupPath\$($Policy.Id).json"
}

기본 Default값은 C드라이브에 저장됩니다. 

3. 파일을 더블 클릭하여 메모장으로 열어 정책 명을 확인하실 수 있습니다. 

 

[조건부 액세스 복원 방법]

1. PowerShell 관리자 권한으로 실행합니다.

2. 아래의 명령어를 입력하여 조건부 액세스 정책을 Restore를 진행합니다.

<#
.SYNOPSIS
    Restore Conditional Access Policies from JSON files
.DESCRIPTION
    This script uses JSON files in a folder to create new Conditional Access Policies.
    The JSON files should be created with Get-AzureADMSConditionalAccessPolicy
.EXAMPLE
    .\RestoreCA -BackupPath C:\Temp\AzureAD -Prefix "Restore - "
 
    Creates new policies where "Restore - " is added to the Display name
.PARAMETER BackupPath
    Path to the JSON files. Files will be searched recursively
.PARAMETER Prefix
    A prefix that is added to the display name of the policies
.NOTES
    Barbara Forbes
    4bes.nl
#>
param(
    [parameter()]
    [String]$BackupPath,
    [parameter()]
    [string]$Prefix
)
 
Connect-AzureAD
 
$BackupJsons = Get-ChildItem $BackupPath -Recurse -Include *.json
foreach ($Json in $BackupJsons) {
 
    $policy = Get-Content $Json.FullName | ConvertFrom-Json
    $policy.DisplayName
 
    # Create objects for the conditions and GrantControls
    [Microsoft.Open.MSGraph.Model.ConditionalAccessConditionSet]$Conditions = $Policy.Conditions
    [Microsoft.Open.MSGraph.Model.ConditionalAccessGrantControls]$GrantControls = $Policy.GrantControls
    [Microsoft.Open.MSGraph.Model.ConditionalAccessSessionControls]$SessionControls = $Policy.SessionControls
   
    # Create an object for the users.
    # By going through the members we only add properties that are not null
    $OldUsers = $Policy.Conditions.Users
    $UserMembers = $OldUsers | Get-Member -MemberType NoteProperty
    $Users = New-Object Microsoft.Open.MSGraph.Model.ConditionalAccessUserCondition
    foreach ($member in $UserMembers) {
        if (-not[string]::IsNullOrEmpty($OldUsers.$($member.Name))) {
            $Users.($member.Name) = ($OldUsers.$($member.Name))
        }
    }
    $Conditions.Users = $Users
 
    # Do the same thing for the applications
    $OldApplications = $Policy.Conditions.Applications
    $ApplicationMembers = $OldApplications | Get-Member -MemberType NoteProperty
    $Applications = New-Object Microsoft.Open.MSGraph.Model.ConditionalAccessApplicationCondition
    foreach ($member in $ApplicationMembers) {
        if (-not[string]::IsNullOrEmpty($OldApplications.$($member.Name))) {
            $Applications.($member.Name) = ($OldApplications.$($member.Name))
        }
    }
    $Conditions.Applications = $Applications
    $NewDisplayName = $Prefix + $Policy.DisplayName
    $Parameters = @{
        DisplayName     = $NewDisplayName
        State           = $policy.State
        Conditions      = $Conditions
        GrantControls   = $GrantControls
        SessionControls = $SessionControls
    }
 
   $null = New-AzureADMSConditionalAccessPolicy @Parameters
}

3. 아래와 같이 조건부 액세스 정책이 Restore된 것을 확인하실 수 있습니다.

+ Recent posts