Private/Remove-NSPConditionalAccessTravelRecord.ps1
|
function Remove-NSPConditionalAccessTravelRecord { <# .SYNOPSIS After a travel policy is retired: drops its ownership record and its travel entry from the tenant profile. #> [CmdletBinding(SupportsShouldProcess)] param( [Parameter(Mandatory)][string]$TenantId, [Parameter(Mandatory)][string]$ProfilePath, [Parameter(Mandatory)][string]$DefinitionId, [string]$TravelKey, [string]$ConfigRoot ) if (-not $PSCmdlet.ShouldProcess($DefinitionId, 'Remove travel entry and ownership record')) { return } $ownershipPath = Join-Path (Get-NSPConditionalAccessLocalPath -Kind Ownership -ConfigRoot $ConfigRoot) "$TenantId.json" if (Test-Path -LiteralPath $ownershipPath) { $record = Get-Content -LiteralPath $ownershipPath -Raw | ConvertFrom-Json if ($record.Policies -and $record.Policies.PSObject.Properties[$DefinitionId]) { $record.Policies.PSObject.Properties.Remove($DefinitionId) Save-NSPConditionalAccessJson -InputObject $record -Path $ownershipPath } } $tenantProfile = Get-Content -LiteralPath $ProfilePath -Raw | ConvertFrom-Json if ($TravelKey -and $tenantProfile.Travel -and $tenantProfile.Travel.Entries -and $tenantProfile.Travel.Entries.PSObject.Properties[$TravelKey]) { $tenantProfile.Travel.Entries.PSObject.Properties.Remove($TravelKey) Save-NSPConditionalAccessJson -InputObject $tenantProfile -Path $ProfilePath } } |