backup/Backup-AutopilotDevices.ps1
|
#Requires -Version 7.0 function Backup-AutopilotDevices { [CmdletBinding()] param( [Parameter(Mandatory)] [string]$BackupPath, [Parameter(Mandatory)] [SecureString]$Token, [hashtable]$ScopeTagMap = @{} ) try { $folder = Join-Path $BackupPath 'Autopilot Devices' $uri = '/beta/deviceManagement/windowsAutopilotDeviceIdentities' $items = Invoke-GraphRequest2 -Uri $uri -Token $Token foreach ($item in $items) { # use id as filename $fileName = $item.id # remove the id from the saved content $itemCopy = $item | Select-Object -Property * -ExcludeProperty id $clean = Remove-VolatileKeys -InputObject $itemCopy Save-BackupItem -Item $clean -Folder $folder -PresetFileName $fileName -ScopeTagMap $ScopeTagMap } Write-Verbose "backed up $($items.Count) autopilot devices to $folder" } catch { Write-Error "failed to backup autopilot devices: $_" return } } Export-ModuleMember -Function Backup-AutopilotDevices |