Public/Invoke-IntuneBackupClientApp.ps1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
function Invoke-IntuneBackupClientApp { <# .SYNOPSIS Backup Intune Client Apps .DESCRIPTION Backup Intune Client Apps as JSON files per Device Compliance Policy to the specified Path. .PARAMETER Path Path to store backup files .EXAMPLE Invoke-IntuneBackupClientApp -Path "C:\temp" #> [CmdletBinding()] param( [Parameter(Mandatory = $true)] [string]$Path, [Parameter(Mandatory = $false)] [ValidateSet("v1.0", "Beta")] [string]$ApiVersion = "Beta" ) # Set the Microsoft Graph API endpoint if (-not ((Get-MSGraphEnvironment).SchemaVersion -eq $apiVersion)) { Update-MSGraphEnvironment -SchemaVersion $apiVersion -Quiet Connect-MSGraph -ForceNonInteractive -Quiet } # Create folder if not exists if (-not (Test-Path "$Path\Client Apps")) { $null = New-Item -Path "$Path\Client Apps" -ItemType Directory } # Get all Client Apps $clientApps = Invoke-MSGraphRequest -Url 'deviceAppManagement/mobileApps?$filter=(microsoft.graph.managedApp/appAvailability%20eq%20null%20or%20microsoft.graph.managedApp/appAvailability%20eq%20%27lineOfBusiness%27%20or%20isAssigned%20eq%20true)' | Get-MSGraphAllPages foreach ($clientApp in $clientApps) { $clientAppType = $clientApp.'@odata.type'.split('.')[-1] $fileName = ($clientApp.displayName).Split([IO.Path]::GetInvalidFileNameChars()) -join '_' $clientAppDetails = Invoke-MSGraphRequest -HttpMethod GET -Url "deviceAppManagement/mobileApps/$($clientApp.id)" $clientAppDetails | ConvertTo-Json | Out-File -LiteralPath "$path\Client Apps\$($clientAppType)_$($fileName).json" [PSCustomObject]@{ "Action" = "Backup" "Type" = "Client App" "Name" = $clientApp.displayName "Path" = "Client Apps\$($clientAppType)_$($fileName).json" } } } |