Scripts/Helpers/RestMethods/Remove-AzRoleAssignmentRestMethod.ps1 (25 lines of code) (raw):
function Remove-AzRoleAssignmentRestMethod {
[CmdletBinding()]
param (
[string] $RoleAssignmentId,
[string] $TenantId,
[string] $ApiVersion
)
if (!$TenantId) {
$response = Invoke-AzRestMethod -Path "$($RoleAssignmentId)?api-version=$ApiVersion" -Method Delete
}
else {
$response = Invoke-AzRestMethod -Path "$($RoleAssignmentId)?api-version=$ApiVersion&tenantId=$($TenantId)" -Method Delete
}
# Process response
$statusCode = $response.StatusCode
if ($statusCode -lt 200 -or $statusCode -ge 300) {
$content = $response.Content
if ($content.Contains("ScopeLocked", [StringComparison]::InvariantCultureIgnoreCase)) {
Write-Warning "Ignoring scope locked error: $($statusCode) -- $($content)"
}
else {
Write-Error "Role assignment deletion failed with error $($statusCode) -- $($content)" -ErrorAction Stop
}
}
}