feat(roles): export built-in Intune roles; fix ASCII header failure

- Drop the ExpiresOn request header. Under an en-US culture its date
  contains U+202F before AM/PM, so every Graph call failed with
  "Request headers must contain only ASCII characters". Nothing reads it.
- Export all role definitions with their assignments, including built-in
  roles (was custom only via isBuiltIn eq false).
- On import, skip creating built-in roles. When Import assignments is on,
  recreate their assignments against the exported role id (built-in ids
  are identical across tenants). Custom-role behaviour is unchanged.
This commit is contained in:
2026-11-24 11:34:52 +01:00
parent 60a655e6d4
commit 37ac448d94
4 changed files with 35 additions and 6 deletions
+24 -4
View File
@@ -677,7 +677,6 @@ function Invoke-InitializeModule
Id = "RoleDefinitions"
ViewID = "IntuneGraphAPI"
API = "/deviceManagement/roleDefinitions"
QUERYLIST = "`$filter=isBuiltIn%20eq%20false"
PostExportCommand = { Start-PostExportRoleDefinitions @args }
PreImportCommand = { Start-PreImportRoleDefinitions @args }
PostFileImportCommand = { Start-PostFileImportRoleDefinitions @args }
@@ -3499,17 +3498,38 @@ function Start-PostExportRoleDefinitions
function Start-PreImportRoleDefinitions
{
param($obj, $objectType)
param($obj, $objectType, $file)
Remove-Property $obj "RoleAssignments"
Remove-Property $obj "RoleAssignments@odata.context"
$tmpObj = Get-GraphObjectFromFile $file
if($tmpObj.isBuiltIn -eq $true -or $tmpObj.isBuiltInRoleDefinition -eq $true)
{
# Built-in roles cannot be created and have the same id in every tenant.
# Only recreate their assignments, and only when assignments are imported.
if($global:chkImportAssignments -and $global:chkImportAssignments.IsChecked -eq $true)
{
Import-RoleDefinitionAssignments $tmpObj.Id $tmpObj
}
else
{
Write-Log "Skipping built-in role '$($tmpObj.displayName)'. Enable 'Import assignments' to import its role assignments" 2
}
return @{ "Import" = $false }
}
}
function Start-PostFileImportRoleDefinitions
{
param($obj, $objectType, $file)
$tmpObj = Get-GraphObjectFromFile $file
Import-RoleDefinitionAssignments $obj.Id (Get-GraphObjectFromFile $file)
}
function Import-RoleDefinitionAssignments
{
param($roleDefinitionId, $tmpObj)
$loadedScopeTags = $global:LoadedDependencyObjects["ScopeTags"]
if(($tmpObj.RoleAssignments | measure).Count -gt 0 -and ($loadedScopeTags | measure).Count -gt 0)
@@ -3523,7 +3543,7 @@ function Start-PostFileImportRoleDefinitions
"displayName"= $roleAssignment.DisplayName
"members" = $roleAssignment.members
"resourceScopes" = $roleAssignment.resourceScopes
"roleDefinition@odata.bind" = "https://graph.microsoft.com/beta/deviceManagement/roleDefinitions('$($obj.Id)')"
"roleDefinition@odata.bind" = "https://graph.microsoft.com/beta/deviceManagement/roleDefinitions('$($roleDefinitionId)')"
"roleScopeTags@odata.bind" = @()
}