Entra / Microsoft 365 · Applications
Update app lock instance
Update Entra ID applications that don't have app instance lock set.
Connect & set up
Run these once per session. All scopes are read-only unless the script makes changes.
Connect-MgGraph -NoWelcome -Scopes Application.ReadWrite.All
Run it
The main script. Copy it, or download the .ps1 and run it from your console.
Connect-MgGraph -NoWelcome -Scopes Application.ReadWrite.AllWrite-Host "Finding Entra ID applications..."[array]$Apps = Get-MgApplication -All | Sort-Object DisplayNameWrite-Host ("Found {0} applications. Now checking the app instance lock" -f $Apps.count)# Create the hash table with the properties to update$AppInstanceLockConfiguration = @{}$AppInstanceLockConfiguration.Add("isEnabled",$true)$AppInstanceLockConfiguration.Add("AllProperties",$true)$Report = [System.Collections.Generic.List[Object]]::new()# Loop through the apps and update each one that doesn't have app instance lock setForEach ($App in $Apps) {$ServiceLock = $App | Select-Object -ExpandProperty ServicePrincipalLockConfigurationWrite-Host ("Now processing {0}" -f $App.displayName)If ($ServiceLock.IsEnabled -eq $True) {Write-Host ("The {0} app is already enabled" -f $App.displayName) -ForegroundColor Red} Else {Write-Host ("App Instance Property Lock Not enabled for {0}; updating app" -f $App.displayName)Update-MgApplication -ApplicationId $App.Id -ServicePrincipalLockConfiguration $AppInstanceLockConfiguration$AppData = [PSCustomObject][Ordered]@{Timestamp = Get-Date -Format sApp = $App.displayNameAppId = $App.IdCreated = $App.CreatedDateTimeSignInAudience = $App.SignInAudienceCredentials = ($App.PasswordCredentials.DisplayName -join ", ")}$Report.Add($AppData)}}$Report | Out-GridView
Attribution
Author
Office365itpros