Skip to content

Commit ac2d462

Browse files
custom apps
1 parent b0c42a2 commit ac2d462

4 files changed

Lines changed: 394 additions & 653 deletions

File tree

Modules/CIPPCore/Public/Add-CIPPW32ScriptApplication.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ function Add-CIPPW32ScriptApplication {
5454
throw "Choco.App.xml not found at: $ChocoXmlFile (Current directory: $PWD)"
5555
}
5656

57-
# Parse the Choco XML to get encryption info
57+
# Parse the Choco XML to get encryption info. We need a wrapper around the application and this is a tiny intune file, perfect for our purpose.
5858
[xml]$ChocoXml = Get-Content $ChocoXmlFile
5959
$EncryptionInfo = @{
6060
EncryptionKey = $ChocoXml.ApplicationInfo.EncryptionInfo.EncryptionKey

Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Applications/Push-UploadApplication.ps1

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,12 @@ function Push-UploadApplication {
8181

8282
# Build parameters dynamically
8383
$Params = @{
84-
AppBody = $intuneBody
85-
TenantFilter = $tenant
86-
FilePath = $Infile
87-
FileName = $Intunexml.ApplicationInfo.FileName
84+
AppBody = $intuneBody
85+
TenantFilter = $tenant
86+
FilePath = $Infile
87+
FileName = $Intunexml.ApplicationInfo.FileName
8888
UnencryptedSize = [int64]$Intunexml.ApplicationInfo.UnencryptedContentSize
89-
EncryptionInfo = $EncryptionInfo
89+
EncryptionInfo = $EncryptionInfo
9090
}
9191
if ($AppConfig.Applicationname) { $Params.DisplayName = $AppConfig.Applicationname }
9292

@@ -106,12 +106,12 @@ function Push-UploadApplication {
106106

107107
# Build parameters dynamically
108108
$Params = @{
109-
AppBody = $intuneBody
110-
TenantFilter = $tenant
111-
FilePath = $Infile
112-
FileName = $Intunexml.ApplicationInfo.FileName
109+
AppBody = $intuneBody
110+
TenantFilter = $tenant
111+
FilePath = $Infile
112+
FileName = $Intunexml.ApplicationInfo.FileName
113113
UnencryptedSize = [int64]$Intunexml.ApplicationInfo.UnencryptedContentSize
114-
EncryptionInfo = $EncryptionInfo
114+
EncryptionInfo = $EncryptionInfo
115115
}
116116
if ($AppConfig.Applicationname) { $Params.DisplayName = $AppConfig.Applicationname }
117117

@@ -139,13 +139,14 @@ function Push-UploadApplication {
139139
if ($AppConfig.description) { $Properties['description'] = $AppConfig.description }
140140
if ($AppConfig.publisher) { $Properties['publisher'] = $AppConfig.publisher }
141141
if ($AppConfig.uninstallScript) { $Properties['uninstallScript'] = $AppConfig.uninstallScript }
142-
if ($AppConfig.detectionScript) { $Properties['detectionScript'] = $AppConfig.detectionScript }
142+
if ($AppConfig.detectionPath) { $Properties['detectionPath'] = $AppConfig.detectionPath }
143+
if ($AppConfig.detectionFile) { $Properties['detectionFile'] = $AppConfig.detectionFile }
143144
if ($AppConfig.runAsAccount) { $Properties['runAsAccount'] = $AppConfig.runAsAccount }
144145
if ($AppConfig.deviceRestartBehavior) { $Properties['deviceRestartBehavior'] = $AppConfig.deviceRestartBehavior }
145146
if ($null -ne $AppConfig.runAs32Bit) { $Properties['runAs32Bit'] = $AppConfig.runAs32Bit }
146147
if ($null -ne $AppConfig.enforceSignatureCheck) { $Properties['enforceSignatureCheck'] = $AppConfig.enforceSignatureCheck }
147148

148-
$NewApp = Add-CIPPW32ScriptApplication -TenantFilter $tenant -Properties ([PSCustomObject]$Properties) -FilePath $Infile -FileName $Intunexml.ApplicationInfo.FileName -UnencryptedSize ([int64]$Intunexml.ApplicationInfo.UnencryptedContentSize) -EncryptionInfo $EncryptionInfo
149+
$NewApp = Add-CIPPW32ScriptApplication -TenantFilter $tenant -Properties ([PSCustomObject]$Properties)
149150
}
150151
'WinGetNew' {
151152
# I think we don't need a separate WinGetNew type, just use WinGet?
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
function Invoke-AddWin32ScriptApp {
2+
<#
3+
.FUNCTIONALITY
4+
Entrypoint,AnyTenant
5+
.ROLE
6+
Endpoint.Application.ReadWrite
7+
#>
8+
[CmdletBinding()]
9+
param($Request, $TriggerMetadata)
10+
11+
$APIName = $Request.Params.CIPPEndpoint
12+
$Headers = $Request.Headers
13+
14+
$Win32ScriptApp = $Request.Body
15+
$AssignTo = $Win32ScriptApp.AssignTo -eq 'customGroup' ? $Win32ScriptApp.CustomGroup : $Win32ScriptApp.AssignTo
16+
17+
# Validate required fields
18+
if ([string]::IsNullOrEmpty($Win32ScriptApp.ApplicationName) -and [string]::IsNullOrEmpty($Win32ScriptApp.applicationName)) {
19+
return ([HttpResponseContext]@{
20+
StatusCode = [HttpStatusCode]::BadRequest
21+
Body = @{ Results = @('Application name is required') }
22+
})
23+
}
24+
25+
if ([string]::IsNullOrEmpty($Win32ScriptApp.installScript)) {
26+
return ([HttpResponseContext]@{
27+
StatusCode = [HttpStatusCode]::BadRequest
28+
Body = @{ Results = @('Install script is required') }
29+
})
30+
}
31+
32+
# Use whichever case was provided
33+
$AppName = if ($Win32ScriptApp.ApplicationName) { $Win32ScriptApp.ApplicationName } else { $Win32ScriptApp.applicationName }
34+
35+
$AllowedTenants = Test-CIPPAccess -Request $Request -TenantList
36+
$Tenants = ($Request.Body.selectedTenants | Where-Object { $AllowedTenants -contains $_.customerId -or $AllowedTenants -contains 'AllTenants' }).defaultDomainName
37+
38+
$Results = foreach ($Tenant in $Tenants) {
39+
try {
40+
$CompleteObject = [PSCustomObject]@{
41+
tenant = $Tenant
42+
Applicationname = $AppName
43+
assignTo = $AssignTo
44+
InstallationIntent = $Win32ScriptApp.InstallationIntent
45+
type = 'Win32ScriptApp'
46+
description = $Win32ScriptApp.description
47+
publisher = $Win32ScriptApp.publisher
48+
installScript = $Win32ScriptApp.installScript
49+
uninstallScript = $Win32ScriptApp.uninstallScript
50+
detectionPath = $Win32ScriptApp.detectionPath
51+
detectionFile = $Win32ScriptApp.detectionFile
52+
runAsAccount = if ($Win32ScriptApp.InstallAsSystem) { 'system' } else { 'user' }
53+
deviceRestartBehavior = if ($Win32ScriptApp.DisableRestart) { 'suppress' } else { 'allow' }
54+
runAs32Bit = [bool]$Win32ScriptApp.runAs32Bit
55+
enforceSignatureCheck = [bool]$Win32ScriptApp.enforceSignatureCheck
56+
} | ConvertTo-Json -Depth 15
57+
58+
$Table = Get-CippTable -tablename 'apps'
59+
$Table.Force = $true
60+
Add-CIPPAzDataTableEntity @Table -Entity @{
61+
JSON = "$CompleteObject"
62+
RowKey = "$((New-Guid).GUID)"
63+
PartitionKey = 'apps'
64+
status = 'Not Deployed yet'
65+
}
66+
"Successfully added Win32 Script App for $($Tenant) to queue."
67+
Write-LogMessage -headers $Headers -API $APIName -tenant $Tenant -message "Successfully added Win32 Script App $AppName to queue" -Sev 'Info'
68+
} catch {
69+
Write-LogMessage -headers $Headers -API $APIName -tenant $Tenant -message "Failed to add Win32 Script App $AppName to queue. Error: $($_.Exception.Message)" -Sev 'Error'
70+
"Failed to add Win32 Script App for $($Tenant) to queue: $($_.Exception.Message)"
71+
}
72+
}
73+
74+
$body = [PSCustomObject]@{ 'Results' = $Results }
75+
76+
return ([HttpResponseContext]@{
77+
StatusCode = [HttpStatusCode]::OK
78+
Body = $body
79+
})
80+
}

0 commit comments

Comments
 (0)