@@ -11,15 +11,11 @@ function Push-UploadApplication {
1111 $Filter = " PartitionKey eq 'apps' and RowKey eq '$ ( $Item.Name ) '"
1212
1313 $AppConfig = (Get-CIPPAzDataTableEntity @Table - filter $Filter ).JSON | ConvertFrom-Json
14- $intuneBody = $AppConfig.IntuneBody
1514 $tenants = if ($AppConfig.tenant -eq ' AllTenants' ) {
1615 (Get-Tenants - IncludeErrors).defaultDomainName
1716 } else {
1817 $AppConfig.tenant
1918 }
20- $assignTo = $AppConfig.assignTo
21- $AssignToIntent = $AppConfig.InstallationIntent
22- $ExcludeGroup = $AppConfig.excludeGroup
2319 $ClearRow = Get-CIPPAzDataTableEntity @Table - Filter $Filter
2420 if ($AppConfig.tenant -ne ' AllTenants' ) {
2521 $null = Remove-AzDataTableEntity - Force @Table - Entity $clearRow
@@ -33,142 +29,9 @@ function Push-UploadApplication {
3329 }
3430 }
3531
36- # Determine app type (default to 'Choco' if not specified)
37- $AppType = if ($AppConfig.type ) { $AppConfig.type } else { ' Choco' }
38-
39- # Load files based on app type (only for types that need them)
40- $Intunexml = $null
41- $Infile = $null
42- if ($AppType -eq ' MSPApp' ) {
43- [xml ]$Intunexml = Get-Content (Join-Path $env: CIPPRootPath " AddMSPApp\$ ( $AppConfig.MSPAppName ) .app.xml" )
44- $Infile = Join-Path $env: CIPPRootPath " AddMSPApp\$ ( $AppConfig.MSPAppName ) .intunewin"
45- } elseif ($AppType -in @ (' Choco' , ' Win32ScriptApp' )) {
46- [xml ]$Intunexml = Get-Content (Join-Path $env: CIPPRootPath ' AddChocoApp\Choco.App.xml' )
47- $Infile = Join-Path $env: CIPPRootPath " AddChocoApp\$ ( $Intunexml.ApplicationInfo.FileName ) "
48- }
49-
50-
51- $baseuri = ' https://graph.microsoft.com/beta/deviceAppManagement/mobileApps'
5232 foreach ($tenant in $tenants ) {
5333 try {
54- # Check if app already exists
55- $ApplicationList = New-GraphGetRequest - Uri $baseuri - tenantid $tenant | Where-Object { $_.DisplayName -eq $AppConfig.Applicationname -and ($_ .' @odata.type' -eq ' #microsoft.graph.win32LobApp' -or $_ .' @odata.type' -eq ' #microsoft.graph.winGetApp' ) }
56- if ($ApplicationList.displayname.count -ge 1 ) {
57- Write-LogMessage - api ' AppUpload' - tenant $tenant - message " $ ( $AppConfig.Applicationname ) exists. Skipping this application" - Sev ' Info'
58- continue
59- }
60-
61- # Route to appropriate handler based on app type
62- $NewApp = $null
63- switch ($AppType ) {
64- ' WinGet' {
65- $NewApp = Add-CIPPWinGetApp - AppBody $intuneBody - TenantFilter $tenant
66- }
67- ' Choco' {
68- # Prepare encryption info from XML
69- $EncryptionInfo = @ {
70- EncryptionKey = $Intunexml.ApplicationInfo.EncryptionInfo.EncryptionKey
71- MacKey = $Intunexml.ApplicationInfo.EncryptionInfo.MacKey
72- InitializationVector = $Intunexml.ApplicationInfo.EncryptionInfo.InitializationVector
73- Mac = $Intunexml.ApplicationInfo.EncryptionInfo.Mac
74- ProfileIdentifier = $Intunexml.ApplicationInfo.EncryptionInfo.ProfileIdentifier
75- FileDigest = $Intunexml.ApplicationInfo.EncryptionInfo.FileDigest
76- FileDigestAlgorithm = $Intunexml.ApplicationInfo.EncryptionInfo.FileDigestAlgorithm
77- }
78-
79- # Build parameters dynamically
80- $Params = @ {
81- AppBody = $intuneBody
82- TenantFilter = $tenant
83- FilePath = $Infile
84- FileName = $Intunexml.ApplicationInfo.FileName
85- UnencryptedSize = [int64 ]$Intunexml.ApplicationInfo.UnencryptedContentSize
86- EncryptionInfo = $EncryptionInfo
87- }
88- if ($AppConfig.Applicationname ) { $Params.DisplayName = $AppConfig.Applicationname }
89-
90- $NewApp = Add-CIPPPackagedApplication @Params
91- }
92- ' MSPApp' {
93- # Prepare encryption info from XML
94- $EncryptionInfo = @ {
95- EncryptionKey = $Intunexml.ApplicationInfo.EncryptionInfo.EncryptionKey
96- MacKey = $Intunexml.ApplicationInfo.EncryptionInfo.MacKey
97- InitializationVector = $Intunexml.ApplicationInfo.EncryptionInfo.InitializationVector
98- Mac = $Intunexml.ApplicationInfo.EncryptionInfo.Mac
99- ProfileIdentifier = $Intunexml.ApplicationInfo.EncryptionInfo.ProfileIdentifier
100- FileDigest = $Intunexml.ApplicationInfo.EncryptionInfo.FileDigest
101- FileDigestAlgorithm = $Intunexml.ApplicationInfo.EncryptionInfo.FileDigestAlgorithm
102- }
103-
104- # Build parameters dynamically
105- $Params = @ {
106- AppBody = $intuneBody
107- TenantFilter = $tenant
108- FilePath = $Infile
109- FileName = $Intunexml.ApplicationInfo.FileName
110- UnencryptedSize = [int64 ]$Intunexml.ApplicationInfo.UnencryptedContentSize
111- EncryptionInfo = $EncryptionInfo
112- }
113- if ($AppConfig.Applicationname ) { $Params.DisplayName = $AppConfig.Applicationname }
114-
115- $NewApp = Add-CIPPPackagedApplication @Params
116- }
117- ' Win32ScriptApp' {
118- # Prepare encryption info from XML
119- $EncryptionInfo = @ {
120- EncryptionKey = $Intunexml.ApplicationInfo.EncryptionInfo.EncryptionKey
121- MacKey = $Intunexml.ApplicationInfo.EncryptionInfo.MacKey
122- InitializationVector = $Intunexml.ApplicationInfo.EncryptionInfo.InitializationVector
123- Mac = $Intunexml.ApplicationInfo.EncryptionInfo.Mac
124- ProfileIdentifier = $Intunexml.ApplicationInfo.EncryptionInfo.ProfileIdentifier
125- FileDigest = $Intunexml.ApplicationInfo.EncryptionInfo.FileDigest
126- FileDigestAlgorithm = $Intunexml.ApplicationInfo.EncryptionInfo.FileDigestAlgorithm
127- }
128-
129- # Build properties dynamically
130- $Properties = @ {
131- displayName = $AppConfig.Applicationname
132- installScript = $AppConfig.installScript
133- }
134-
135- # A few of these are probably mandatory
136- if ($AppConfig.description ) { $Properties [' description' ] = $AppConfig.description }
137- if ($AppConfig.publisher ) { $Properties [' publisher' ] = $AppConfig.publisher }
138- if ($AppConfig.uninstallScript ) { $Properties [' uninstallScript' ] = $AppConfig.uninstallScript }
139- if ($AppConfig.detectionScript ) { $Properties [' detectionScript' ] = $AppConfig.detectionScript }
140- if ($AppConfig.detectionPath ) { $Properties [' detectionPath' ] = $AppConfig.detectionPath }
141- if ($AppConfig.detectionFile ) { $Properties [' detectionFile' ] = $AppConfig.detectionFile }
142- if ($AppConfig.runAsAccount ) { $Properties [' runAsAccount' ] = $AppConfig.runAsAccount }
143- if ($AppConfig.deviceRestartBehavior ) { $Properties [' deviceRestartBehavior' ] = $AppConfig.deviceRestartBehavior }
144- if ($null -ne $AppConfig.runAs32Bit ) { $Properties [' runAs32Bit' ] = $AppConfig.runAs32Bit }
145- if ($null -ne $AppConfig.enforceSignatureCheck ) { $Properties [' enforceSignatureCheck' ] = $AppConfig.enforceSignatureCheck }
146-
147- $NewApp = Add-CIPPW32ScriptApplication - TenantFilter $tenant - Properties ([PSCustomObject ]$Properties )
148- }
149- ' WinGetNew' {
150- # I think we don't need a separate WinGetNew type, just use WinGet?
151- }
152- default {
153- throw " Unsupported app type: $ ( $AppConfig.type ) "
154- }
155- }
156-
157- # Log success and assign app if requested
158- if ($NewApp ) {
159- Write-LogMessage - api ' AppUpload' - tenant $tenant - message " $ ( $AppConfig.Applicationname ) Successfully created" - Sev ' Info'
160-
161- if ($assignTo -and $assignTo -ne ' On' ) {
162- $intent = if ($AssignToIntent ) { ' Uninstall' } else { ' Required' }
163- $AppTypeForAssignment = switch ($AppType ) {
164- ' WinGet' { ' WinGet' }
165- ' WinGetNew' { ' WinGet' }
166- default { ' Win32Lob' }
167- }
168- Start-Sleep - Milliseconds 200
169- Set-CIPPAssignedApplication - ApplicationId $NewApp.Id - TenantFilter $tenant - groupName $assignTo - ExcludeGroup $ExcludeGroup - Intent $intent - AppType $AppTypeForAssignment - APIName ' AppUpload'
170- }
171- }
34+ $NewApp = New-CIPPIntuneAppDeployment - AppConfig $AppConfig - TenantFilter $tenant - APIName ' AppUpload'
17235 } catch {
17336 " Failed to add Application for $tenant : $ ( $_.Exception.Message ) "
17437 Write-LogMessage - api ' AppUpload' - tenant $tenant - message " Failed adding Application $ ( $AppConfig.Applicationname ) . Error: $ ( $_.Exception.Message ) " - LogData (Get-CippException - Exception $_ ) - Sev ' Error'
0 commit comments