Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions IntuneBackupAndRestore/Public/Invoke-IntuneRestoreClientApps.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
function Invoke-IntuneRestoreClientApps {
<#
.SYNOPSIS
Restore Intune Client Apps

.DESCRIPTION
Restore Intune Client Apps from JSON files per Client App from the specified Path.

.PARAMETER Path
Root path where backup files are located, created with the Invoke-IntuneBackupConfigurationPolicy function

.EXAMPLE
Invoke-IntuneRestoreClientApps -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
}

# Get all Client Apps
$clientApps = Get-ChildItem -Path "$Path\Client Apps" -File

foreach ($clientapp in $clientApps) {
$clientappContent = Get-Content -LiteralPath $clientapp.FullName -Raw | ConvertFrom-Json

# Remove properties that are not available for creating a new configuration
$requestBody = $clientappContent | Select-Object -Property * -ExcludeProperty "@odata.context", uploadState, publishingState, isAssigned, dependentAppCount, supersedingAppCount, supersededAppCount, id, createdDateTime, lastModifiedDateTime, settingCount, creationSource | ConvertTo-Json -Depth 100

# Restore the Settings Catalog Policy
try {
$null = Invoke-MSGraphRequest -HttpMethod POST -Content $requestBody.toString() -Url "deviceAppManagement/mobileApps" -ErrorAction Stop
[PSCustomObject]@{
"Action" = "Restore"
"Type" = "Client App"
"Name" = $clientapp.FullName
"Path" = "Client Apps\$($clientapp.Name)"
}
}
catch {
Write-Verbose "$($clientapp.FullName) - Failed to restore Client App" -Verbose
Write-Error $_ -ErrorAction Continue
$streamReader = [System.IO.StreamReader]::new($_.Exception.Response.GetResponseStream())
$ErrResp = $streamReader.ReadToEnd() | ConvertFrom-Json
$streamReader.Close()
}
$ErrResp
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@ function Start-IntuneRestoreConfig() {
Invoke-IntuneRestoreGroupPolicyConfiguration -Path $Path
Invoke-IntuneRestoreDeviceManagementIntent -Path $Path
Invoke-IntuneRestoreAppProtectionPolicy -Path $Path
Invoke-IntuneRestoreClientApps -Path $Path
}