Skip to content

Commit 8ea61a8

Browse files
authored
Merge pull request KelvinTegelaar#1699 from kris6673/issue4846
Fix: Office App deployment issues
2 parents 4f447e8 + 72fe57e commit 8ea61a8

File tree

1 file changed

+24
-21
lines changed

1 file changed

+24
-21
lines changed

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Endpoint/Applications/Invoke-AddOfficeApp.ps1

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,25 @@ function Invoke-AddOfficeApp {
99
param($Request, $TriggerMetadata)
1010

1111
# Input bindings are passed in via param block.
12-
$Tenants = $Request.body.selectedTenants.defaultDomainName
12+
$Tenants = $Request.Body.selectedTenants.defaultDomainName
13+
$Headers = $Request.Headers
14+
$APIName = $Request.Params.CIPPEndpoint
1315
if ('AllTenants' -in $Tenants) { $Tenants = (Get-Tenants).defaultDomainName }
14-
$AssignTo = if ($request.body.Assignto -ne 'on') { $request.body.Assignto }
16+
$AssignTo = if ($Request.Body.AssignTo -ne 'on') { $Request.Body.AssignTo }
1517

16-
$results = foreach ($Tenant in $tenants) {
18+
$Results = foreach ($Tenant in $Tenants) {
1719
try {
18-
$ExistingO365 = New-graphGetRequest -Uri 'https://graph.microsoft.com/beta/deviceAppManagement/mobileApps' -tenantid $tenant | Where-Object { $_.displayname -eq 'Microsoft 365 Apps for Windows 10 and later' }
20+
$ExistingO365 = New-GraphGetRequest -Uri 'https://graph.microsoft.com/beta/deviceAppManagement/mobileApps' -tenantid $Tenant | Where-Object { $_.displayName -eq 'Microsoft 365 Apps for Windows 10 and later' }
1921
if (!$ExistingO365) {
2022
# Check if custom XML is provided
21-
if ($request.body.useCustomXml -and $request.body.customXml) {
23+
if ($Request.Body.useCustomXml -and $Request.Body.customXml) {
2224
# Use custom XML configuration
2325
$ObjBody = [pscustomobject]@{
2426
'@odata.type' = '#microsoft.graph.officeSuiteApp'
2527
'displayName' = 'Microsoft 365 Apps for Windows 10 and later'
2628
'description' = 'Microsoft 365 Apps for Windows 10 and later'
2729
'informationUrl' = 'https://products.office.com/en-us/explore-office-for-home'
30+
'privacyInformationUrl' = 'https://privacy.microsoft.com/en-us/privacystatement'
2831
'isFeatured' = $true
2932
'publisher' = 'Microsoft'
3033
'notes' = ''
@@ -38,7 +41,7 @@ function Invoke-AddOfficeApp {
3841
}
3942
} else {
4043
# Use standard configuration
41-
$Arch = if ($request.body.arch) { 'x64' } else { 'x86' }
44+
$Arch = if ($Request.Body.arch) { 'x64' } else { 'x86' }
4245
$products = @('o365ProPlusRetail')
4346
$ExcludedApps = [pscustomobject]@{
4447
infoPath = $true
@@ -54,26 +57,27 @@ function Invoke-AddOfficeApp {
5457
access = $false
5558
bing = $false
5659
}
57-
foreach ($ExcludedApp in $request.body.excludedApps.value) {
58-
$ExcludedApps.$excludedapp = $true
60+
foreach ($ExcludedApp in $Request.Body.excludedApps.value) {
61+
$ExcludedApps.$ExcludedApp = $true
5962
}
6063
$ObjBody = [pscustomobject]@{
6164
'@odata.type' = '#microsoft.graph.officeSuiteApp'
6265
'displayName' = 'Microsoft 365 Apps for Windows 10 and later'
6366
'description' = 'Microsoft 365 Apps for Windows 10 and later'
6467
'informationUrl' = 'https://products.office.com/en-us/explore-office-for-home'
68+
'privacyInformationUrl' = 'https://privacy.microsoft.com/en-us/privacystatement'
6569
'isFeatured' = $true
6670
'publisher' = 'Microsoft'
6771
'notes' = ''
6872
'owner' = 'Microsoft'
69-
'autoAcceptEula' = [bool]$request.body.AcceptLicense
73+
'autoAcceptEula' = [bool]$Request.Body.AcceptLicense
7074
'excludedApps' = $ExcludedApps
7175
'officePlatformArchitecture' = $Arch
7276
'officeSuiteAppDefaultFileFormat' = 'OfficeOpenXMLFormat'
73-
'localesToInstall' = @($request.body.languages.value)
74-
'shouldUninstallOlderVersionsOfOffice' = [bool]$request.body.RemoveVersions
75-
'updateChannel' = $request.body.updateChannel.value
76-
'useSharedComputerActivation' = [bool]$request.body.SharedComputerActivation
77+
'localesToInstall' = @($Request.Body.languages.value)
78+
'shouldUninstallOlderVersionsOfOffice' = [bool]$Request.Body.RemoveVersions
79+
'updateChannel' = $Request.Body.updateChannel.value
80+
'useSharedComputerActivation' = [bool]$Request.Body.SharedComputerActivation
7781
'productIds' = $products
7882
'largeIcon' = @{
7983
'@odata.type' = 'microsoft.graph.mimeContent'
@@ -88,25 +92,24 @@ function Invoke-AddOfficeApp {
8892
"Office deployment already exists for $($Tenant)"
8993
continue
9094
}
91-
Write-LogMessage -headers $Request.Headers -API $APIName -tenant $($tenant) -message "Added Office profile to $($tenant)" -Sev 'Info'
95+
Write-LogMessage -headers $Headers -API $APIName -tenant $($Tenant) -message "Added Office profile to $($Tenant)" -Sev 'Info'
9296
if ($AssignTo) {
9397
$AssignO365 = if ($AssignTo -ne 'AllDevicesAndUsers') { '{"mobileAppAssignments":[{"@odata.type":"#microsoft.graph.mobileAppAssignment","target":{"@odata.type":"#microsoft.graph.' + $($AssignTo) + 'AssignmentTarget"},"intent":"Required"}]}' } else { '{"mobileAppAssignments":[{"@odata.type":"#microsoft.graph.mobileAppAssignment","target":{"@odata.type":"#microsoft.graph.allDevicesAssignmentTarget"},"intent":"Required"},{"@odata.type":"#microsoft.graph.mobileAppAssignment","target":{"@odata.type":"#microsoft.graph.allLicensedUsersAssignmentTarget"},"intent":"Required"}]}' } Write-Host ($AssignO365)
94-
New-graphPostRequest -Uri "https://graph.microsoft.com/beta/deviceAppManagement/mobileApps/$($OfficeAppID.id)/assign" -tenantid $tenant -Body $AssignO365 -type POST
95-
Write-LogMessage -headers $Request.Headers -API $APIName -tenant $($tenant) -message "Assigned Office to $AssignTo" -Sev 'Info'
98+
New-GraphPOSTRequest -Uri "https://graph.microsoft.com/beta/deviceAppManagement/mobileApps/$($OfficeAppID.id)/assign" -tenantid $Tenant -Body $AssignO365 -type POST
99+
Write-LogMessage -headers $Headers -API $APIName -tenant $($Tenant) -message "Assigned Office to $AssignTo" -Sev 'Info'
96100
}
97101
"Successfully added Office App for $($Tenant)"
98102
} catch {
99-
"Failed to add Office App for $($Tenant): $($_.Exception.Message)"
100-
Write-LogMessage -headers $Request.Headers -API $APIName -tenant $($tenant) -message "Failed to add Office App. Error: $($_.Exception.Message)" -Sev 'Error'
103+
$ErrorMessage = Get-CippException -Exception $_
104+
"Failed to add Office App for $($Tenant): $($ErrorMessage.NormalizedError)"
105+
Write-LogMessage -headers $Headers -API $APIName -tenant $($Tenant) -message "Failed to add Office App. Error: $($ErrorMessage.NormalizedError)" -Sev 'Error' -Logdata $ErrorMessage
101106
continue
102107
}
103108

104109
}
105110

106-
$body = [pscustomobject]@{'Results' = $results }
107-
108111
return ([HttpResponseContext]@{
109112
StatusCode = [HttpStatusCode]::OK
110-
Body = $body
113+
Body = @{'Results' = $Results }
111114
})
112115
}

0 commit comments

Comments
 (0)