Skip to content

Commit 09c821d

Browse files
committed
app deployment standard tweaks
1 parent 497b750 commit 09c821d

File tree

2 files changed

+48
-20
lines changed

2 files changed

+48
-20
lines changed

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Tenant/Administration/Application Approval/Invoke-ListAppApprovalTemplates.ps1

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,10 @@ function Invoke-ListAppApprovalTemplates {
5353
}
5454
}
5555

56-
Write-LogMessage -headers $Headers -API $APIName -message "Listed App Deployment Templates: $($Body.Count) templates found" -Sev 'Info'
5756
} catch {
5857
$Body = @{
5958
Results = "Failed to list app deployment templates: $($_.Exception.Message)"
6059
}
61-
Write-LogMessage -headers $Headers -API $APIName -message "Failed to list App Deployment Templates: $($_.Exception.Message)" -Sev 'Error'
6260
}
6361

6462
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{

Modules/CIPPCore/Public/Standards/Invoke-CIPPStandardAppDeploy.ps1

Lines changed: 48 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,34 +29,63 @@ function Invoke-CIPPStandardAppDeploy {
2929
#>
3030

3131
param($Tenant, $Settings)
32+
Write-Information "Running AppDeploy standard for tenant $($Tenant)."
33+
3234
$AppsToAdd = $Settings.appids -split ','
3335
$AppExists = New-GraphGetRequest -uri 'https://graph.microsoft.com/beta/servicePrincipals?$top=999' -tenantid $Tenant
36+
$Mode = $Settings.mode ?? 'copy'
37+
38+
if ($Mode -eq 'template') {
39+
$AppsToAdd = $Settings.templateIds.addedFields.AppId
40+
}
3441

42+
$MissingApps = foreach ($App in $AppsToAdd) {
43+
if ($App -notin $AppExists.appId) {
44+
$App
45+
}
46+
}
3547
if ($Settings.remediate -eq $true) {
36-
foreach ($App In $AppsToAdd) {
37-
$App = $App.Trim()
38-
if (!$App) {
39-
continue
48+
if ($Mode -eq 'copy') {
49+
foreach ($App in $AppsToAdd) {
50+
$App = $App.Trim()
51+
if (!$App) {
52+
continue
53+
}
54+
$Application = $AppExists | Where-Object -Property appId -EQ $App
55+
try {
56+
New-CIPPApplicationCopy -App $App -Tenant $Tenant
57+
Write-LogMessage -API 'Standards' -tenant $tenant -message "Added application $($Application.displayName) ($App) to $Tenant and updated it's permissions" -sev Info
58+
} catch {
59+
$ErrorMessage = Get-NormalizedError -Message $_.Exception.Message
60+
Write-LogMessage -API 'Standards' -tenant $tenant -message "Failed to add app $($Application.displayName) ($App). Error: $ErrorMessage" -sev Error
61+
}
62+
}
63+
} elseif ($Mode -eq 'template') {
64+
$TemplateIds = $Settings.templateIds.value
65+
$TemplateName = $Settings.templateIds.label
66+
$AppIds = $Settings.templateIds.addedFields.AppId
67+
68+
foreach ($AppId in $AppIds) {
69+
if ($AppId -notin $AppExists.appId) {
70+
Write-Information "Adding $($AppId) to tenant $($Tenant)."
71+
$PostResults = New-GraphPostRequest 'https://graph.microsoft.com/beta/servicePrincipals' -type POST -tenantid $Item.tenant -body "{ `"appId`": `"$($Item.appId)`" }"
72+
Write-LogMessage -message "Added $($Item.AppId) to tenant $($Item.Tenant)" -tenant $Item.Tenant -API 'Add Multitenant App' -sev Info
73+
}
4074
}
41-
$Application = $AppExists | Where-Object -Property appId -EQ $App
42-
try {
43-
New-CIPPApplicationCopy -App $App -Tenant $Tenant
44-
Write-LogMessage -API 'Standards' -tenant $tenant -message "Added application $($Application.displayName) ($App) to $Tenant and updated it's permissions" -sev Info
45-
} catch {
46-
$ErrorMessage = Get-NormalizedError -Message $_.Exception.Message
47-
Write-LogMessage -API 'Standards' -tenant $tenant -message "Failed to add app $($Application.displayName) ($App). Error: $ErrorMessage" -sev Error
75+
foreach ($TemplateId in $TemplateIds) {
76+
try {
77+
Add-CIPPApplicationPermission -TemplateId $TemplateId -Tenantfilter $Tenant
78+
Add-CIPPDelegatedPermission -TemplateId $TemplateId -Tenantfilter $Tenant
79+
Write-LogMessage -API 'Standards' -tenant $tenant -message "Added application(s) from template $($TemplateName) and updated it's permissions" -sev Info
80+
} catch {
81+
$ErrorMessage = Get-NormalizedError -Message $_.Exception.Message
82+
Write-LogMessage -API 'Standards' -tenant $tenant -message "Failed to add app from approval template $($TemplateName). Error: $ErrorMessage" -sev Error
83+
}
4884
}
4985
}
5086
}
5187

5288
if ($Settings.alert) {
53-
54-
$MissingApps = foreach ($App in $AppsToAdd) {
55-
if ($App -notin $AppExists.appId) {
56-
$App
57-
}
58-
}
59-
6089
if ($MissingApps.Count -gt 0) {
6190
Write-StandardsAlert -message "The following applications are not deployed: $($MissingApps -join ', ')" -object (@{ 'Missing Apps' = $MissingApps -join ',' }) -tenant $Tenant -standardName 'AppDeploy' -standardId $Settings.standardId
6291
Write-LogMessage -API 'Standards' -tenant $tenant -message "The following applications are not deployed: $($MissingApps -join ', ')" -sev Info
@@ -70,4 +99,5 @@ function Invoke-CIPPStandardAppDeploy {
7099
Set-CIPPStandardsCompareField -FieldName 'standards.AppDeploy' -FieldValue $StateIsCorrect -TenantFilter $tenant
71100
Add-CIPPBPAField -FieldName 'AppDeploy' -FieldValue $StateIsCorrect -StoreAs bool -Tenant $tenant
72101
}
102+
73103
}

0 commit comments

Comments
 (0)