backup/Backup-WindowsEnrollmentProfiles.ps1
|
#Requires -Version 7.0 function Backup-WindowsEnrollmentProfiles { [CmdletBinding()] param( [Parameter(Mandatory)] [string]$BackupPath, [Parameter(Mandatory)] [SecureString]$Token, [hashtable]$ScopeTagMap = @{} ) try { $folder = Join-Path $BackupPath 'Enrollment Profiles' 'Windows' $uri = '/beta/deviceManagement/windowsAutopilotDeploymentProfiles' $items = Invoke-GraphRequest2 -Uri $uri -Token $Token foreach ($item in $items) { $assignments = Resolve-Assignments -AssignmentsUri "/beta/deviceManagement/windowsAutopilotDeploymentProfiles/$($item.id)/assignments" -Token $Token if ($assignments) { $item | Add-Member -MemberType NoteProperty -Name 'assignments' -Value $assignments -Force } # construct filename $odataType = $item.'@odata.type' $type = $odataType -replace '#microsoft\.graph\.', '' $fileName = "$($item.displayName)_$type" $clean = Remove-VolatileKeys -InputObject $item Save-BackupItem -Item $clean -Folder $folder -FileName $fileName -ScopeTagMap $ScopeTagMap } Write-Verbose "backed up $($items.Count) Windows enrollment profiles to $folder" } catch { Write-Error "failed to backup Windows enrollment profiles: $_" return } } Export-ModuleMember -Function Backup-WindowsEnrollmentProfiles |