@@ -406,36 +406,56 @@ exit 0
406406
407407 if ($ExistingHash -eq $SettingsHash ) {
408408 Write-LogMessage - API ' Standards' - tenant $Tenant - message " $AppDisplayName settings unchanged — skipping redeploy" - sev Info
409- return
410- }
409+ } else {
410+ foreach ($App in @ ($ExistingApps )) {
411+ $null = New-GraphPostRequest - Uri " $Baseuri /$ ( $App.id ) " - Type DELETE - tenantid $Tenant
412+ Write-LogMessage - API ' Standards' - tenant $Tenant - message " Removed existing $AppDisplayName app to redeploy with updated settings" - sev Info
413+ }
414+ Start-Sleep - Seconds 2
415+
416+ # Deploy the Win32 script app
417+ $AppProperties = [PSCustomObject ]@ {
418+ displayName = $AppDisplayName
419+ description = $AppDescription
420+ publisher = ' CIPP'
421+ installScript = $InstallScript
422+ uninstallScript = $UninstallScript
423+ detectionScript = $DetectionScript
424+ runAsAccount = ' system'
425+ deviceRestartBehavior = ' suppress'
426+ }
427+
428+ $NewApp = Add-CIPPW32ScriptApplication - TenantFilter $Tenant - Properties $AppProperties
411429
412- foreach ($App in @ ($ExistingApps )) {
413- $null = New-GraphPostRequest - Uri " $Baseuri /$ ( $App.id ) " - Type DELETE - tenantid $Tenant
414- Write-LogMessage - API ' Standards' - tenant $Tenant - message " Removed existing $AppDisplayName app to redeploy with updated settings" - sev Info
430+ if ($NewApp -and $AssignTo -ne ' On' ) {
431+ Start-Sleep - Milliseconds 500
432+ Set-CIPPAssignedApplication - ApplicationId $NewApp.Id - TenantFilter $Tenant - GroupName $AssignTo - Intent ' Required' - AppType ' Win32Lob' - APIName ' Standards'
433+ }
434+
435+ Write-LogMessage - API ' Standards' - tenant $Tenant - message " Successfully deployed $AppDisplayName " - sev Info
436+ }
437+ } else {
438+ # App doesn't exist yet — deploy it
439+ $AppProperties = [PSCustomObject ]@ {
440+ displayName = $AppDisplayName
441+ description = $AppDescription
442+ publisher = ' CIPP'
443+ installScript = $InstallScript
444+ uninstallScript = $UninstallScript
445+ detectionScript = $DetectionScript
446+ runAsAccount = ' system'
447+ deviceRestartBehavior = ' suppress'
415448 }
416- Start-Sleep - Seconds 2
417- }
418449
419- # Deploy the Win32 script app
420- $AppProperties = [PSCustomObject ]@ {
421- displayName = $AppDisplayName
422- description = $AppDescription
423- publisher = ' CIPP'
424- installScript = $InstallScript
425- uninstallScript = $UninstallScript
426- detectionScript = $DetectionScript
427- runAsAccount = ' system'
428- deviceRestartBehavior = ' suppress'
429- }
450+ $NewApp = Add-CIPPW32ScriptApplication - TenantFilter $Tenant - Properties $AppProperties
430451
431- $NewApp = Add-CIPPW32ScriptApplication - TenantFilter $Tenant - Properties $AppProperties
452+ if ($NewApp -and $AssignTo -ne ' On' ) {
453+ Start-Sleep - Milliseconds 500
454+ Set-CIPPAssignedApplication - ApplicationId $NewApp.Id - TenantFilter $Tenant - GroupName $AssignTo - Intent ' Required' - AppType ' Win32Lob' - APIName ' Standards'
455+ }
432456
433- if ($NewApp -and $AssignTo -ne ' On' ) {
434- Start-Sleep - Milliseconds 500
435- Set-CIPPAssignedApplication - ApplicationId $NewApp.Id - TenantFilter $Tenant - GroupName $AssignTo - Intent ' Required' - AppType ' Win32Lob' - APIName ' Standards'
457+ Write-LogMessage - API ' Standards' - tenant $Tenant - message " Successfully deployed $AppDisplayName " - sev Info
436458 }
437-
438- Write-LogMessage - API ' Standards' - tenant $Tenant - message " Successfully deployed $AppDisplayName " - sev Info
439459 }
440460
441461 if ($Settings.alert -eq $true ) {
@@ -449,7 +469,6 @@ exit 0
449469
450470 if ($Settings.report -eq $true ) {
451471 $StateIsCorrect = $AppExists
452-
453472 $ExpectedValue = [PSCustomObject ]@ {
454473 AppDeployed = $true
455474 }
0 commit comments