From 1d9b177dd15f14de50bdec90be90d41ef4feee3a Mon Sep 17 00:00:00 2001 From: Christian Oeser Date: Fri, 16 Aug 2024 15:21:33 +0200 Subject: [PATCH 1/7] Added AutoUpdateSupersededApps to GroupAssignment --- Public/Add-IntuneWin32AppAssignmentGroup.ps1 | 31 +++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/Public/Add-IntuneWin32AppAssignmentGroup.ps1 b/Public/Add-IntuneWin32AppAssignmentGroup.ps1 index 69c211a..b37a515 100644 --- a/Public/Add-IntuneWin32AppAssignmentGroup.ps1 +++ b/Public/Add-IntuneWin32AppAssignmentGroup.ps1 @@ -29,6 +29,9 @@ function Add-IntuneWin32AppAssignmentGroup { .PARAMETER DeadlineTime Specify a date time object for the deadline of the assignment. + + .PARAMETER AutoUpdateSupersededApps + Specify to automatically update superseded app using default value of 'notConfigured'. .PARAMETER UseLocalTime Specify to use either UTC of device local time for the assignment, set to 'True' for device local time and 'False' for UTC. @@ -58,7 +61,7 @@ function Add-IntuneWin32AppAssignmentGroup { Author: Nickolaj Andersen Contact: @NickolajA Created: 2020-09-20 - Updated: 2023-09-20 + Updated: 2024-08-16 Version history: 1.0.0 - (2020-09-20) Function created @@ -67,6 +70,7 @@ function Add-IntuneWin32AppAssignmentGroup { 1.0.3 - (2021-08-31) Updated to use new authentication header 1.0.4 - (2023-09-04) Updated with Test-AccessToken function 1.0.5 - (2023-09-20) Updated with FilterName and FilterMode parameters + 1.0.6 - (2024-08-16) Updated with autoUpdateSettings parameters #> [CmdletBinding(SupportsShouldProcess = $true)] param( @@ -114,6 +118,11 @@ function Add-IntuneWin32AppAssignmentGroup { [ValidateSet("notConfigured", "foreground")] [string]$DeliveryOptimizationPriority = "notConfigured", + [parameter(Mandatory = $false, HelpMessage = "Specify to automatically update superseded app using default value of 'notConfigured'.")] + [ValidateNotNullOrEmpty()] + [ValidateSet("notConfigured", "enabled", "unknownFutureValue")] + [string]$AutoUpdateSupersededApps = "notConfigured", + [parameter(Mandatory = $false, ParameterSetName = "GroupInclude", HelpMessage = "Specify whether Restart Grace Period functionality for this assignment should be configured, additional parameter input using at least RestartGracePeriod and RestartCountDownDisplay is required.")] [ValidateNotNullOrEmpty()] [bool]$EnableRestartGracePeriod = $false, @@ -254,6 +263,12 @@ function Add-IntuneWin32AppAssignmentGroup { "source" = "direct" "target" = $TargetAssignment } + + # Construct table for autoUpdate settings + $AutoUpdateSettings = @{ + "autoUpdateSupersededAppsState" = $AutoUpdateSupersededApps + } + switch ($PSCmdlet.ParameterSetName) { "GroupInclude" { $SettingsTable = @{ @@ -261,6 +276,7 @@ function Add-IntuneWin32AppAssignmentGroup { "notifications" = $Notification "restartSettings" = $null "deliveryOptimizationPriority" = $DeliveryOptimizationPriority + "autoUpdateSettings" = $null "installTimeSettings" = $null } $Win32AppAssignmentBody.Add("settings", $SettingsTable) @@ -270,6 +286,19 @@ function Add-IntuneWin32AppAssignmentGroup { } } + if ($AutoUpdateSupersededApps -eq "enable") { + if ($Win32App.supersededAppCount -gt 0) { + Write-Verbose -Message "Detected that Win32 app has an app to supersed" + + $Win32AppAssignmentBody.settings.autoUpdateSettings = @{ + "autoUpdateSupersededAppsState" = $AutoUpdateSupersededApps + } + } + else { + Write-Warning -Message "Win32 app was not configured for superseding an app. Please add a superseding relationship." + } + } + # Amend installTimeSettings property if Available parameter is specified if (($PSBoundParameters["AvailableTime"]) -and (-not($PSBoundParameters["DeadlineTime"]))) { $Win32AppAssignmentBody.settings.installTimeSettings = @{ From 775b17ea00fba27417bf2c1233e3817bf159304a Mon Sep 17 00:00:00 2001 From: Christian Oeser Date: Fri, 16 Aug 2024 15:37:43 +0200 Subject: [PATCH 2/7] fixed autoupodate --- Public/Add-IntuneWin32AppAssignmentGroup.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Public/Add-IntuneWin32AppAssignmentGroup.ps1 b/Public/Add-IntuneWin32AppAssignmentGroup.ps1 index b37a515..20d03ea 100644 --- a/Public/Add-IntuneWin32AppAssignmentGroup.ps1 +++ b/Public/Add-IntuneWin32AppAssignmentGroup.ps1 @@ -286,8 +286,8 @@ function Add-IntuneWin32AppAssignmentGroup { } } - if ($AutoUpdateSupersededApps -eq "enable") { - if ($Win32App.supersededAppCount -gt 0) { + if ($AutoUpdateSupersededApps -eq "enabled") { + if ($Win32App.supersededAppCount -ne 0) { Write-Verbose -Message "Detected that Win32 app has an app to supersed" $Win32AppAssignmentBody.settings.autoUpdateSettings = @{ From 7600acb5a0c8e5523bbfec373f4b57e56702dfde Mon Sep 17 00:00:00 2001 From: Christian Oeser Date: Mon, 19 Aug 2024 12:24:06 +0200 Subject: [PATCH 3/7] Updated with autoUpdateSettings parameters --- .../Add-IntuneWin32AppAssignmentAllDevices.ps1 | 18 ++++++++++++++++++ .../Add-IntuneWin32AppAssignmentAllUsers.ps1 | 18 ++++++++++++++++++ Public/Add-IntuneWin32AppAssignmentGroup.ps1 | 6 ++++-- Samples/6-Assignments.ps1 | 3 +++ 4 files changed, 43 insertions(+), 2 deletions(-) diff --git a/Public/Add-IntuneWin32AppAssignmentAllDevices.ps1 b/Public/Add-IntuneWin32AppAssignmentAllDevices.ps1 index 02d33d2..d35deee 100644 --- a/Public/Add-IntuneWin32AppAssignmentAllDevices.ps1 +++ b/Public/Add-IntuneWin32AppAssignmentAllDevices.ps1 @@ -21,6 +21,9 @@ function Add-IntuneWin32AppAssignmentAllDevices { .PARAMETER DeadlineTime Specify a date time object for the deadline of the assignment. + .PARAMETER AutoUpdateSupersededApps + Specify to automatically update superseded app using default value of 'notConfigured'. + .PARAMETER UseLocalTime Specify to use either UTC of device local time for the assignment, set to 'True' for device local time and 'False' for UTC. @@ -56,6 +59,7 @@ function Add-IntuneWin32AppAssignmentAllDevices { 1.0.1 - (2021-04-01) Updated token expired message to a warning instead of verbose output 1.0.2 - (2021-08-31) Updated to use new authentication header 1.0.3 - (2023-09-04) Updated with Test-AccessToken function + 1.0.4 - (2024-08-19) Updated with autoUpdateSettings parameters #> [CmdletBinding(SupportsShouldProcess = $true)] param( @@ -90,6 +94,11 @@ function Add-IntuneWin32AppAssignmentAllDevices { [ValidateSet("notConfigured", "foreground")] [string]$DeliveryOptimizationPriority = "notConfigured", + [parameter(Mandatory = $false, HelpMessage = "Specify to automatically update superseded app using default value of 'notConfigured'.")] + [ValidateNotNullOrEmpty()] + [ValidateSet("notConfigured", "enabled", "unknownFutureValue")] + [string]$AutoUpdateSupersededApps = "notConfigured", + [parameter(Mandatory = $false, HelpMessage = "Specify whether Restart Grace Period functionality for this assignment should be configured, additional parameter input using at least RestartGracePeriod and RestartCountDownDisplay is required.")] [ValidateNotNullOrEmpty()] [bool]$EnableRestartGracePeriod = $false, @@ -206,12 +215,21 @@ function Add-IntuneWin32AppAssignmentAllDevices { "source" = "direct" "target" = $TargetAssignment } + + # Construct table for autoUpdate settings + if($AutoUpdateSupersededApps -eq "enabled"){if($Win32App.supersededAppCount -eq 0){$AutoUpdateSupersededApps = "notConfigured"}} + + $AutoUpdateSettings = @{ + "autoUpdateSupersededAppsState" = $AutoUpdateSupersededApps + } + $SettingsTable = @{ "@odata.type" = "#microsoft.graph.win32LobAppAssignmentSettings" "notifications" = $Notification "restartSettings" = $null "deliveryOptimizationPriority" = $DeliveryOptimizationPriority "installTimeSettings" = $null + "autoUpdateSettings" = $AutoUpdateSettings } $Win32AppAssignmentBody.Add("settings", $SettingsTable) diff --git a/Public/Add-IntuneWin32AppAssignmentAllUsers.ps1 b/Public/Add-IntuneWin32AppAssignmentAllUsers.ps1 index 7618fac..e762a11 100644 --- a/Public/Add-IntuneWin32AppAssignmentAllUsers.ps1 +++ b/Public/Add-IntuneWin32AppAssignmentAllUsers.ps1 @@ -21,6 +21,9 @@ function Add-IntuneWin32AppAssignmentAllUsers { .PARAMETER DeadlineTime Specify a date time object for the deadline of the assignment. + .PARAMETER AutoUpdateSupersededApps + Specify to automatically update superseded app using default value of 'notConfigured'. + .PARAMETER UseLocalTime Specify to use either UTC of device local time for the assignment, set to 'True' for device local time and 'False' for UTC. @@ -56,6 +59,7 @@ function Add-IntuneWin32AppAssignmentAllUsers { 1.0.1 - (2021-04-01) Updated token expired message to a warning instead of verbose output 1.0.2 - (2021-08-31) Updated to use new authentication header 1.0.3 - (2023-09-04) Updated with Test-AccessToken function + 1.0.4 - (2024-08-19) Updated with autoUpdateSettings parameters #> [CmdletBinding(SupportsShouldProcess = $true)] param( @@ -90,6 +94,11 @@ function Add-IntuneWin32AppAssignmentAllUsers { [ValidateSet("notConfigured", "foreground")] [string]$DeliveryOptimizationPriority = "notConfigured", + [parameter(Mandatory = $false, HelpMessage = "Specify to automatically update superseded app using default value of 'notConfigured'.")] + [ValidateNotNullOrEmpty()] + [ValidateSet("notConfigured", "enabled", "unknownFutureValue")] + [string]$AutoUpdateSupersededApps = "notConfigured", + [parameter(Mandatory = $false, HelpMessage = "Specify whether Restart Grace Period functionality for this assignment should be configured, additional parameter input using at least RestartGracePeriod and RestartCountDownDisplay is required.")] [ValidateNotNullOrEmpty()] [bool]$EnableRestartGracePeriod = $false, @@ -206,12 +215,21 @@ function Add-IntuneWin32AppAssignmentAllUsers { "source" = "direct" "target" = $TargetAssignment } + + # Construct table for autoUpdate settings + if($AutoUpdateSupersededApps -eq "enabled"){if($Win32App.supersededAppCount -eq 0){$AutoUpdateSupersededApps = "notConfigured"}} + + $AutoUpdateSettings = @{ + "autoUpdateSupersededAppsState" = $AutoUpdateSupersededApps + } + $SettingsTable = @{ "@odata.type" = "#microsoft.graph.win32LobAppAssignmentSettings" "notifications" = $Notification "restartSettings" = $null "deliveryOptimizationPriority" = $DeliveryOptimizationPriority "installTimeSettings" = $null + "autoUpdateSettings" = $AutoUpdateSettings } $Win32AppAssignmentBody.Add("settings", $SettingsTable) diff --git a/Public/Add-IntuneWin32AppAssignmentGroup.ps1 b/Public/Add-IntuneWin32AppAssignmentGroup.ps1 index 20d03ea..bb23ae8 100644 --- a/Public/Add-IntuneWin32AppAssignmentGroup.ps1 +++ b/Public/Add-IntuneWin32AppAssignmentGroup.ps1 @@ -70,7 +70,7 @@ function Add-IntuneWin32AppAssignmentGroup { 1.0.3 - (2021-08-31) Updated to use new authentication header 1.0.4 - (2023-09-04) Updated with Test-AccessToken function 1.0.5 - (2023-09-20) Updated with FilterName and FilterMode parameters - 1.0.6 - (2024-08-16) Updated with autoUpdateSettings parameters + 1.0.6 - (2024-08-19) Updated with autoUpdateSettings parameters #> [CmdletBinding(SupportsShouldProcess = $true)] param( @@ -265,6 +265,8 @@ function Add-IntuneWin32AppAssignmentGroup { } # Construct table for autoUpdate settings + if($AutoUpdateSupersededApps -eq "enabled"){if($Win32App.supersededAppCount -eq 0){$AutoUpdateSupersededApps = "notConfigured"}} + $AutoUpdateSettings = @{ "autoUpdateSupersededAppsState" = $AutoUpdateSupersededApps } @@ -276,8 +278,8 @@ function Add-IntuneWin32AppAssignmentGroup { "notifications" = $Notification "restartSettings" = $null "deliveryOptimizationPriority" = $DeliveryOptimizationPriority - "autoUpdateSettings" = $null "installTimeSettings" = $null + "autoUpdateSettings" = $AutoUpdateSettings } $Win32AppAssignmentBody.Add("settings", $SettingsTable) } diff --git a/Samples/6-Assignments.ps1 b/Samples/6-Assignments.ps1 index 8afe583..ba3fcda 100644 --- a/Samples/6-Assignments.ps1 +++ b/Samples/6-Assignments.ps1 @@ -32,6 +32,7 @@ $AssignmentArgs = @{ "EnableRestartGracePeriod" = $true "RestartNotificationSnooze" = 220 "Verbose" = $true + "AutoUpdateSupersededApps" = "enabled" } Add-IntuneWin32AppAssignmentGroup @AssignmentArgs @@ -72,6 +73,7 @@ $AssignmentArgs = @{ "EnableRestartGracePeriod" = $true "RestartNotificationSnooze" = 220 "Verbose" = $true + "AutoUpdateSupersededApps" = "enabled" } Add-IntuneWin32AppAssignmentAllDevices @AssignmentArgs @@ -97,5 +99,6 @@ $AssignmentArgs = @{ "EnableRestartGracePeriod" = $true "RestartNotificationSnooze" = 220 "Verbose" = $true + "AutoUpdateSupersededApps" = "enabled" } Add-IntuneWin32AppAssignmentAllUsers @AssignmentArgs \ No newline at end of file From 61b317206226d3d5f24e0724f541f0b5db100d09 Mon Sep 17 00:00:00 2001 From: Christian Oeser Date: Tue, 20 Aug 2024 15:48:29 +0200 Subject: [PATCH 4/7] Removed Unused Function and updated documentation --- .../Add-IntuneWin32AppAssignmentAllDevices.ps1 | 4 ++-- Public/Add-IntuneWin32AppAssignmentAllUsers.ps1 | 4 ++-- Public/Add-IntuneWin32AppAssignmentGroup.ps1 | 17 ++--------------- 3 files changed, 6 insertions(+), 19 deletions(-) diff --git a/Public/Add-IntuneWin32AppAssignmentAllDevices.ps1 b/Public/Add-IntuneWin32AppAssignmentAllDevices.ps1 index d35deee..f1ef31d 100644 --- a/Public/Add-IntuneWin32AppAssignmentAllDevices.ps1 +++ b/Public/Add-IntuneWin32AppAssignmentAllDevices.ps1 @@ -52,14 +52,14 @@ function Add-IntuneWin32AppAssignmentAllDevices { Author: Nickolaj Andersen Contact: @NickolajA Created: 2020-09-20 - Updated: 2023-09-04 + Updated: 2024-08-20 Version history: 1.0.0 - (2020-09-20) Function created 1.0.1 - (2021-04-01) Updated token expired message to a warning instead of verbose output 1.0.2 - (2021-08-31) Updated to use new authentication header 1.0.3 - (2023-09-04) Updated with Test-AccessToken function - 1.0.4 - (2024-08-19) Updated with autoUpdateSettings parameters + 1.0.4 - (2024-08-20) Updated with autoUpdateSettings parameters #> [CmdletBinding(SupportsShouldProcess = $true)] param( diff --git a/Public/Add-IntuneWin32AppAssignmentAllUsers.ps1 b/Public/Add-IntuneWin32AppAssignmentAllUsers.ps1 index e762a11..cf88b94 100644 --- a/Public/Add-IntuneWin32AppAssignmentAllUsers.ps1 +++ b/Public/Add-IntuneWin32AppAssignmentAllUsers.ps1 @@ -52,14 +52,14 @@ function Add-IntuneWin32AppAssignmentAllUsers { Author: Nickolaj Andersen Contact: @NickolajA Created: 2020-09-20 - Updated: 2023-09-04 + Updated: 2024-08-20 Version history: 1.0.0 - (2020-09-20) Function created 1.0.1 - (2021-04-01) Updated token expired message to a warning instead of verbose output 1.0.2 - (2021-08-31) Updated to use new authentication header 1.0.3 - (2023-09-04) Updated with Test-AccessToken function - 1.0.4 - (2024-08-19) Updated with autoUpdateSettings parameters + 1.0.4 - (2024-08-20) Updated with autoUpdateSettings parameters #> [CmdletBinding(SupportsShouldProcess = $true)] param( diff --git a/Public/Add-IntuneWin32AppAssignmentGroup.ps1 b/Public/Add-IntuneWin32AppAssignmentGroup.ps1 index bb23ae8..e01d902 100644 --- a/Public/Add-IntuneWin32AppAssignmentGroup.ps1 +++ b/Public/Add-IntuneWin32AppAssignmentGroup.ps1 @@ -61,7 +61,7 @@ function Add-IntuneWin32AppAssignmentGroup { Author: Nickolaj Andersen Contact: @NickolajA Created: 2020-09-20 - Updated: 2024-08-16 + Updated: 2024-08-20 Version history: 1.0.0 - (2020-09-20) Function created @@ -70,7 +70,7 @@ function Add-IntuneWin32AppAssignmentGroup { 1.0.3 - (2021-08-31) Updated to use new authentication header 1.0.4 - (2023-09-04) Updated with Test-AccessToken function 1.0.5 - (2023-09-20) Updated with FilterName and FilterMode parameters - 1.0.6 - (2024-08-19) Updated with autoUpdateSettings parameters + 1.0.6 - (2024-08-20) Updated with autoUpdateSettings parameters #> [CmdletBinding(SupportsShouldProcess = $true)] param( @@ -288,19 +288,6 @@ function Add-IntuneWin32AppAssignmentGroup { } } - if ($AutoUpdateSupersededApps -eq "enabled") { - if ($Win32App.supersededAppCount -ne 0) { - Write-Verbose -Message "Detected that Win32 app has an app to supersed" - - $Win32AppAssignmentBody.settings.autoUpdateSettings = @{ - "autoUpdateSupersededAppsState" = $AutoUpdateSupersededApps - } - } - else { - Write-Warning -Message "Win32 app was not configured for superseding an app. Please add a superseding relationship." - } - } - # Amend installTimeSettings property if Available parameter is specified if (($PSBoundParameters["AvailableTime"]) -and (-not($PSBoundParameters["DeadlineTime"]))) { $Win32AppAssignmentBody.settings.installTimeSettings = @{ From 5ddff84bcd45c0ebacd3a0e3bfa72a573534f817 Mon Sep 17 00:00:00 2001 From: Christian Oeser Date: Tue, 3 Sep 2024 10:50:46 +0200 Subject: [PATCH 5/7] reworked AutoUpdateSupersededApps Feature --- ...Add-IntuneWin32AppAssignmentAllDevices.ps1 | 32 +++++++++++++---- .../Add-IntuneWin32AppAssignmentAllUsers.ps1 | 34 ++++++++++++++++--- Public/Add-IntuneWin32AppAssignmentGroup.ps1 | 29 +++++++--------- 3 files changed, 67 insertions(+), 28 deletions(-) diff --git a/Public/Add-IntuneWin32AppAssignmentAllDevices.ps1 b/Public/Add-IntuneWin32AppAssignmentAllDevices.ps1 index 02d33d2..1f279da 100644 --- a/Public/Add-IntuneWin32AppAssignmentAllDevices.ps1 +++ b/Public/Add-IntuneWin32AppAssignmentAllDevices.ps1 @@ -90,6 +90,11 @@ function Add-IntuneWin32AppAssignmentAllDevices { [ValidateSet("notConfigured", "foreground")] [string]$DeliveryOptimizationPriority = "notConfigured", + [parameter(Mandatory = $false, HelpMessage = "Specify to automatically update superseded app using default value of 'notConfigured'.")] + [ValidateNotNullOrEmpty()] + [ValidateSet("notConfigured", "enabled", "unknownFutureValue")] + [string]$AutoUpdateSupersededApps = "notConfigured", + [parameter(Mandatory = $false, HelpMessage = "Specify whether Restart Grace Period functionality for this assignment should be configured, additional parameter input using at least RestartGracePeriod and RestartCountDownDisplay is required.")] [ValidateNotNullOrEmpty()] [bool]$EnableRestartGracePeriod = $false, @@ -131,6 +136,13 @@ function Add-IntuneWin32AppAssignmentAllDevices { # Set script variable for error action preference $ErrorActionPreference = "Stop" + # Validate that Deadline parameter input datetime object is in the future if the Available parameter is not passed on the command line + if ($PSBoundParameters["AutoUpdateSupersededApps"]) { + if ($PSBoundParameters["Intent"] -ne "available") { + Write-Warning -Message "Validation failed for parameter input, AutoUpdateSupersededApps is only allowed with Intent equals available."; break + } + } + # Validate that Available parameter input datetime object is in the past if the Deadline parameter is not passed on the command line if ($PSBoundParameters["AvailableTime"]) { if (-not($PSBoundParameters["DeadlineTime"])) { @@ -140,7 +152,7 @@ function Add-IntuneWin32AppAssignmentAllDevices { } } - # Validate that Deadline parameter input datetime object is in the future if the Available parameter is not passed on the command line + ## Validate that Deadline parameter input datetime object is in the future if the Available parameter is not passed on the command line if ($PSBoundParameters["DeadlineTime"]) { if (-not($PSBoundParameters["AvailableTime"])) { if ($DeadlineTime -lt (Get-Date)) { @@ -175,9 +187,9 @@ function Add-IntuneWin32AppAssignmentAllDevices { # Ensure a Filter exist by given name from parameter input Write-Verbose -Message "Querying for specified Filter: $($FilterName)" $AssignmentFilters = Invoke-MSGraphOperation -Get -APIVersion "Beta" -Resource "deviceManagement/assignmentFilters" -Verbose - if ($AssignmentFilters -ne $null) { + if ($null -ne $AssignmentFilters) { $AssignmentFilter = $AssignmentFilters | Where-Object { $PSItem.displayName -eq $FilterName } - if ($AssignmentFilter -ne $null) { + if ($null -ne $AssignmentFilter) { Write-Verbose -Message "Found Filter with display name '$($AssignmentFilter.displayName)' and id: $($AssignmentFilter.id)" } else { @@ -189,14 +201,14 @@ function Add-IntuneWin32AppAssignmentAllDevices { # Retrieve Win32 app by ID from parameter input Write-Verbose -Message "Querying for Win32 app using ID: $($ID)" $Win32App = Invoke-IntuneGraphRequest -APIVersion "Beta" -Resource "mobileApps/$($ID)" -Method "GET" - if ($Win32App -ne $null) { + if ($null -ne $Win32App) { $Win32AppID = $Win32App.id # Construct target assignment body $TargetAssignment = @{ "@odata.type" = "#microsoft.graph.allDevicesAssignmentTarget" - "deviceAndAppManagementAssignmentFilterId" = if ($AssignmentFilter -ne $null) { $AssignmentFilter.id } else { $null } - "deviceAndAppManagementAssignmentFilterType" = if ($AssignmentFilter -ne $null) { $FilterMode } else { "none" } + "deviceAndAppManagementAssignmentFilterId" = if ($null -ne $AssignmentFilter) { $AssignmentFilter.id } else { $null } + "deviceAndAppManagementAssignmentFilterType" = if ($null -ne $AssignmentFilter) { $FilterMode } else { "none" } } # Construct table for Win32 app assignment body @@ -206,6 +218,7 @@ function Add-IntuneWin32AppAssignmentAllDevices { "source" = "direct" "target" = $TargetAssignment } + $SettingsTable = @{ "@odata.type" = "#microsoft.graph.win32LobAppAssignmentSettings" "notifications" = $Notification @@ -215,6 +228,13 @@ function Add-IntuneWin32AppAssignmentAllDevices { } $Win32AppAssignmentBody.Add("settings", $SettingsTable) + # Amend AutoUpdateSupersededApps property if Intent equals available and the app superseeds an other app + if (($Intent -eq "available") -and ($Win32App.supersededAppCount -gt 0)) { + $Win32AppAssignmentBody.settings.autoUpdateSettings = @{ + "autoUpdateSupersededAppsState" = $AutoUpdateSupersededApps + } + } + # Amend installTimeSettings property if Available parameter is specified if (($PSBoundParameters["AvailableTime"]) -and (-not($PSBoundParameters["DeadlineTime"]))) { $Win32AppAssignmentBody.settings.installTimeSettings = @{ diff --git a/Public/Add-IntuneWin32AppAssignmentAllUsers.ps1 b/Public/Add-IntuneWin32AppAssignmentAllUsers.ps1 index 7618fac..5b64c0a 100644 --- a/Public/Add-IntuneWin32AppAssignmentAllUsers.ps1 +++ b/Public/Add-IntuneWin32AppAssignmentAllUsers.ps1 @@ -21,6 +21,9 @@ function Add-IntuneWin32AppAssignmentAllUsers { .PARAMETER DeadlineTime Specify a date time object for the deadline of the assignment. + .PARAMETER AutoUpdateSupersededApps + Specify to automatically update superseded app using default value of 'notConfigured'. + .PARAMETER UseLocalTime Specify to use either UTC of device local time for the assignment, set to 'True' for device local time and 'False' for UTC. @@ -56,6 +59,7 @@ function Add-IntuneWin32AppAssignmentAllUsers { 1.0.1 - (2021-04-01) Updated token expired message to a warning instead of verbose output 1.0.2 - (2021-08-31) Updated to use new authentication header 1.0.3 - (2023-09-04) Updated with Test-AccessToken function + 1.0.4 - (2024-08-19) Updated with autoUpdateSettings parameters #> [CmdletBinding(SupportsShouldProcess = $true)] param( @@ -90,6 +94,11 @@ function Add-IntuneWin32AppAssignmentAllUsers { [ValidateSet("notConfigured", "foreground")] [string]$DeliveryOptimizationPriority = "notConfigured", + [parameter(Mandatory = $false, HelpMessage = "Specify to automatically update superseded app using default value of 'notConfigured'.")] + [ValidateNotNullOrEmpty()] + [ValidateSet("notConfigured", "enabled", "unknownFutureValue")] + [string]$AutoUpdateSupersededApps = "notConfigured", + [parameter(Mandatory = $false, HelpMessage = "Specify whether Restart Grace Period functionality for this assignment should be configured, additional parameter input using at least RestartGracePeriod and RestartCountDownDisplay is required.")] [ValidateNotNullOrEmpty()] [bool]$EnableRestartGracePeriod = $false, @@ -131,6 +140,13 @@ function Add-IntuneWin32AppAssignmentAllUsers { # Set script variable for error action preference $ErrorActionPreference = "Stop" + # Validate that Deadline parameter input datetime object is in the future if the Available parameter is not passed on the command line + if ($PSBoundParameters["AutoUpdateSupersededApps"]) { + if ($PSBoundParameters["Intent"] -ne "available") { + Write-Warning -Message "Validation failed for parameter input, AutoUpdateSupersededApps is only allowed with Intent equals available."; break + } + } + # Validate that Available parameter input datetime object is in the past if the Deadline parameter is not passed on the command line if ($PSBoundParameters["AvailableTime"]) { if (-not($PSBoundParameters["DeadlineTime"])) { @@ -175,9 +191,9 @@ function Add-IntuneWin32AppAssignmentAllUsers { # Ensure a Filter exist by given name from parameter input Write-Verbose -Message "Querying for specified Filter: $($FilterName)" $AssignmentFilters = Invoke-MSGraphOperation -Get -APIVersion "Beta" -Resource "deviceManagement/assignmentFilters" -Verbose - if ($AssignmentFilters -ne $null) { + if ($null -ne $AssignmentFilters) { $AssignmentFilter = $AssignmentFilters | Where-Object { $PSItem.displayName -eq $FilterName } - if ($AssignmentFilter -ne $null) { + if ($null -ne $AssignmentFilter) { Write-Verbose -Message "Found Filter with display name '$($AssignmentFilter.displayName)' and id: $($AssignmentFilter.id)" } else { @@ -189,14 +205,14 @@ function Add-IntuneWin32AppAssignmentAllUsers { # Retrieve Win32 app by ID from parameter input Write-Verbose -Message "Querying for Win32 app using ID: $($ID)" $Win32App = Invoke-IntuneGraphRequest -APIVersion "Beta" -Resource "mobileApps/$($ID)" -Method "GET" - if ($Win32App -ne $null) { + if ($null -ne $Win32App) { $Win32AppID = $Win32App.id # Construct target assignment body $TargetAssignment = @{ "@odata.type" = "#microsoft.graph.allLicensedUsersAssignmentTarget" - "deviceAndAppManagementAssignmentFilterId" = if ($AssignmentFilter -ne $null) { $AssignmentFilter.id } else { $null } - "deviceAndAppManagementAssignmentFilterType" = if ($AssignmentFilter -ne $null) { $FilterMode } else { "none" } + "deviceAndAppManagementAssignmentFilterId" = if ($null -ne $AssignmentFilter) { $AssignmentFilter.id } else { $null } + "deviceAndAppManagementAssignmentFilterType" = if ($null -ne $AssignmentFilter) { $FilterMode } else { "none" } } # Construct table for Win32 app assignment body @@ -206,6 +222,7 @@ function Add-IntuneWin32AppAssignmentAllUsers { "source" = "direct" "target" = $TargetAssignment } + $SettingsTable = @{ "@odata.type" = "#microsoft.graph.win32LobAppAssignmentSettings" "notifications" = $Notification @@ -215,6 +232,13 @@ function Add-IntuneWin32AppAssignmentAllUsers { } $Win32AppAssignmentBody.Add("settings", $SettingsTable) + # Amend AutoUpdateSupersededApps property if Intent equals available and the app superseeds an other app + if (($Intent -eq "available") -and ($Win32App.supersededAppCount -gt 0)) { + $Win32AppAssignmentBody.settings.autoUpdateSettings = @{ + "autoUpdateSupersededAppsState" = $AutoUpdateSupersededApps + } + } + # Amend installTimeSettings property if Available parameter is specified if (($PSBoundParameters["AvailableTime"]) -and (-not($PSBoundParameters["DeadlineTime"]))) { $Win32AppAssignmentBody.settings.installTimeSettings = @{ diff --git a/Public/Add-IntuneWin32AppAssignmentGroup.ps1 b/Public/Add-IntuneWin32AppAssignmentGroup.ps1 index b37a515..b546988 100644 --- a/Public/Add-IntuneWin32AppAssignmentGroup.ps1 +++ b/Public/Add-IntuneWin32AppAssignmentGroup.ps1 @@ -70,7 +70,7 @@ function Add-IntuneWin32AppAssignmentGroup { 1.0.3 - (2021-08-31) Updated to use new authentication header 1.0.4 - (2023-09-04) Updated with Test-AccessToken function 1.0.5 - (2023-09-20) Updated with FilterName and FilterMode parameters - 1.0.6 - (2024-08-16) Updated with autoUpdateSettings parameters + 1.0.6 - (2024-08-19) Updated with autoUpdateSettings parameters #> [CmdletBinding(SupportsShouldProcess = $true)] param( @@ -164,6 +164,13 @@ function Add-IntuneWin32AppAssignmentGroup { # Set script variable for error action preference $ErrorActionPreference = "Stop" + # Validate that Deadline parameter input datetime object is in the future if the Available parameter is not passed on the command line + if ($PSBoundParameters["AutoUpdateSupersededApps"]) { + if ($PSBoundParameters["Intent"] -ne "available") { + Write-Warning -Message "Validation failed for parameter input, AutoUpdateSupersededApps is only allowed with Intent equals available."; break + } + } + # Validate that Available parameter input datetime object is in the past if the Deadline parameter is not passed on the command line if ($PSBoundParameters["AvailableTime"]) { if (-not($PSBoundParameters["DeadlineTime"])) { @@ -264,11 +271,6 @@ function Add-IntuneWin32AppAssignmentGroup { "target" = $TargetAssignment } - # Construct table for autoUpdate settings - $AutoUpdateSettings = @{ - "autoUpdateSupersededAppsState" = $AutoUpdateSupersededApps - } - switch ($PSCmdlet.ParameterSetName) { "GroupInclude" { $SettingsTable = @{ @@ -276,7 +278,6 @@ function Add-IntuneWin32AppAssignmentGroup { "notifications" = $Notification "restartSettings" = $null "deliveryOptimizationPriority" = $DeliveryOptimizationPriority - "autoUpdateSettings" = $null "installTimeSettings" = $null } $Win32AppAssignmentBody.Add("settings", $SettingsTable) @@ -286,16 +287,10 @@ function Add-IntuneWin32AppAssignmentGroup { } } - if ($AutoUpdateSupersededApps -eq "enable") { - if ($Win32App.supersededAppCount -gt 0) { - Write-Verbose -Message "Detected that Win32 app has an app to supersed" - - $Win32AppAssignmentBody.settings.autoUpdateSettings = @{ - "autoUpdateSupersededAppsState" = $AutoUpdateSupersededApps - } - } - else { - Write-Warning -Message "Win32 app was not configured for superseding an app. Please add a superseding relationship." + # Amend AutoUpdateSupersededApps property if Intent equals available and the app superseeds an other app + if (($Intent -eq "available") -and ($Win32App.supersededAppCount -gt 0)) { + $Win32AppAssignmentBody.settings.autoUpdateSettings = @{ + "autoUpdateSupersededAppsState" = $AutoUpdateSupersededApps } } From a4ab6af95a392d4c253591a7d52ea2f6ece32eaf Mon Sep 17 00:00:00 2001 From: Christian Oeser Date: Tue, 3 Sep 2024 11:13:15 +0200 Subject: [PATCH 6/7] Optimized Code --- Public/Add-IntuneWin32AppAssignmentAllUsers.ps1 | 3 --- Public/Add-IntuneWin32AppAssignmentGroup.ps1 | 10 +++++----- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/Public/Add-IntuneWin32AppAssignmentAllUsers.ps1 b/Public/Add-IntuneWin32AppAssignmentAllUsers.ps1 index f419bb0..3d72b7f 100644 --- a/Public/Add-IntuneWin32AppAssignmentAllUsers.ps1 +++ b/Public/Add-IntuneWin32AppAssignmentAllUsers.ps1 @@ -24,9 +24,6 @@ function Add-IntuneWin32AppAssignmentAllUsers { .PARAMETER AutoUpdateSupersededApps Specify to automatically update superseded app using default value of 'notConfigured'. - .PARAMETER AutoUpdateSupersededApps - Specify to automatically update superseded app using default value of 'notConfigured'. - .PARAMETER UseLocalTime Specify to use either UTC of device local time for the assignment, set to 'True' for device local time and 'False' for UTC. diff --git a/Public/Add-IntuneWin32AppAssignmentGroup.ps1 b/Public/Add-IntuneWin32AppAssignmentGroup.ps1 index 93fb0f0..4f3c088 100644 --- a/Public/Add-IntuneWin32AppAssignmentGroup.ps1 +++ b/Public/Add-IntuneWin32AppAssignmentGroup.ps1 @@ -230,9 +230,9 @@ function Add-IntuneWin32AppAssignmentGroup { # Ensure a Filter exist by given name from parameter input Write-Verbose -Message "Querying for specified Filter: $($FilterName)" $AssignmentFilters = Invoke-MSGraphOperation -Get -APIVersion "Beta" -Resource "deviceManagement/assignmentFilters" -Verbose - if ($AssignmentFilters -ne $null) { + if ($null -ne $AssignmentFilters) { $AssignmentFilter = $AssignmentFilters | Where-Object { $PSItem.displayName -eq $FilterName } - if ($AssignmentFilter -ne $null) { + if ($null -ne $AssignmentFilter) { Write-Verbose -Message "Found Filter with display name '$($AssignmentFilter.displayName)' and id: $($AssignmentFilter.id)" } else { @@ -244,7 +244,7 @@ function Add-IntuneWin32AppAssignmentGroup { # Retrieve Win32 app by ID from parameter input Write-Verbose -Message "Querying for Win32 app using ID: $($ID)" $Win32App = Invoke-IntuneGraphRequest -APIVersion "Beta" -Resource "mobileApps/$($ID)" -Method "GET" - if ($Win32App -ne $null) { + if ($null -ne $Win32App) { $Win32AppID = $Win32App.id # Construct target assignment body @@ -258,8 +258,8 @@ function Add-IntuneWin32AppAssignmentGroup { } $TargetAssignment = @{ "@odata.type" = $DataType - "deviceAndAppManagementAssignmentFilterId" = if ($AssignmentFilter -ne $null) { $AssignmentFilter.id } else { $null } - "deviceAndAppManagementAssignmentFilterType" = if ($AssignmentFilter -ne $null) { $FilterMode } else { "none" } + "deviceAndAppManagementAssignmentFilterId" = if ($null -ne $AssignmentFilter) { $AssignmentFilter.id } else { $null } + "deviceAndAppManagementAssignmentFilterType" = if ($null -ne $AssignmentFilter) { $FilterMode } else { "none" } "groupId" = $GroupID } From 2481eda9fdf481bcbbb1f89d8d0a2e893c708950 Mon Sep 17 00:00:00 2001 From: Christian Oeser Date: Tue, 3 Sep 2024 11:46:31 +0200 Subject: [PATCH 7/7] Deleted AvailableTime validation --- Public/Add-IntuneWin32AppAssignmentAllDevices.ps1 | 12 ++---------- Public/Add-IntuneWin32AppAssignmentAllUsers.ps1 | 12 ++---------- Public/Add-IntuneWin32AppAssignmentGroup.ps1 | 12 ++---------- 3 files changed, 6 insertions(+), 30 deletions(-) diff --git a/Public/Add-IntuneWin32AppAssignmentAllDevices.ps1 b/Public/Add-IntuneWin32AppAssignmentAllDevices.ps1 index 14431ed..19fcd64 100644 --- a/Public/Add-IntuneWin32AppAssignmentAllDevices.ps1 +++ b/Public/Add-IntuneWin32AppAssignmentAllDevices.ps1 @@ -52,7 +52,7 @@ function Add-IntuneWin32AppAssignmentAllDevices { Author: Nickolaj Andersen Contact: @NickolajA Created: 2020-09-20 - Updated: 2024-08-20 + Updated: 2024-09-03 Version history: 1.0.0 - (2020-09-20) Function created @@ -60,6 +60,7 @@ function Add-IntuneWin32AppAssignmentAllDevices { 1.0.2 - (2021-08-31) Updated to use new authentication header 1.0.3 - (2023-09-04) Updated with Test-AccessToken function 1.0.4 - (2024-09-03) Updated with autoUpdateSettings parameters + 1.0.5 - (2024-09-03) Deleted AvailableTime validation #> [CmdletBinding(SupportsShouldProcess = $true)] param( @@ -147,15 +148,6 @@ function Add-IntuneWin32AppAssignmentAllDevices { } } - # Validate that Available parameter input datetime object is in the past if the Deadline parameter is not passed on the command line - if ($PSBoundParameters["AvailableTime"]) { - if (-not($PSBoundParameters["DeadlineTime"])) { - if ($AvailableTime -gt (Get-Date).AddDays(-1)) { - Write-Warning -Message "Validation failed for parameter input, available date time needs to be before the current used 'as soon as possible' deadline date and time, with a offset of 1 day"; break - } - } - } - ## Validate that Deadline parameter input datetime object is in the future if the Available parameter is not passed on the command line if ($PSBoundParameters["DeadlineTime"]) { if (-not($PSBoundParameters["AvailableTime"])) { diff --git a/Public/Add-IntuneWin32AppAssignmentAllUsers.ps1 b/Public/Add-IntuneWin32AppAssignmentAllUsers.ps1 index 3d72b7f..44d4fd7 100644 --- a/Public/Add-IntuneWin32AppAssignmentAllUsers.ps1 +++ b/Public/Add-IntuneWin32AppAssignmentAllUsers.ps1 @@ -52,7 +52,7 @@ function Add-IntuneWin32AppAssignmentAllUsers { Author: Nickolaj Andersen Contact: @NickolajA Created: 2020-09-20 - Updated: 2024-08-20 + Updated: 2024-09-03 Version history: 1.0.0 - (2020-09-20) Function created @@ -60,6 +60,7 @@ function Add-IntuneWin32AppAssignmentAllUsers { 1.0.2 - (2021-08-31) Updated to use new authentication header 1.0.3 - (2023-09-04) Updated with Test-AccessToken function 1.0.4 - (2024-09-03) Updated with autoUpdateSettings parameters + 1.0.5 - (2024-09-03) Deleted AvailableTime validation #> [CmdletBinding(SupportsShouldProcess = $true)] param( @@ -147,15 +148,6 @@ function Add-IntuneWin32AppAssignmentAllUsers { } } - # Validate that Available parameter input datetime object is in the past if the Deadline parameter is not passed on the command line - if ($PSBoundParameters["AvailableTime"]) { - if (-not($PSBoundParameters["DeadlineTime"])) { - if ($AvailableTime -gt (Get-Date).AddDays(-1)) { - Write-Warning -Message "Validation failed for parameter input, available date time needs to be before the current used 'as soon as possible' deadline date and time, with a offset of 1 day"; break - } - } - } - # Validate that Deadline parameter input datetime object is in the future if the Available parameter is not passed on the command line if ($PSBoundParameters["DeadlineTime"]) { if (-not($PSBoundParameters["AvailableTime"])) { diff --git a/Public/Add-IntuneWin32AppAssignmentGroup.ps1 b/Public/Add-IntuneWin32AppAssignmentGroup.ps1 index 4f3c088..15b1426 100644 --- a/Public/Add-IntuneWin32AppAssignmentGroup.ps1 +++ b/Public/Add-IntuneWin32AppAssignmentGroup.ps1 @@ -61,7 +61,7 @@ function Add-IntuneWin32AppAssignmentGroup { Author: Nickolaj Andersen Contact: @NickolajA Created: 2020-09-20 - Updated: 2024-08-16 + Updated: 2024-09-03 Version history: 1.0.0 - (2020-09-20) Function created @@ -71,6 +71,7 @@ function Add-IntuneWin32AppAssignmentGroup { 1.0.4 - (2023-09-04) Updated with Test-AccessToken function 1.0.5 - (2023-09-20) Updated with FilterName and FilterMode parameters 1.0.6 - (2024-09-03) Updated with autoUpdateSettings parameters + 1.0.7 - (2024-09-03) Deleted AvailableTime validation #> [CmdletBinding(SupportsShouldProcess = $true)] param( @@ -171,15 +172,6 @@ function Add-IntuneWin32AppAssignmentGroup { } } - # Validate that Available parameter input datetime object is in the past if the Deadline parameter is not passed on the command line - if ($PSBoundParameters["AvailableTime"]) { - if (-not($PSBoundParameters["DeadlineTime"])) { - if ($AvailableTime -gt (Get-Date).AddDays(-1)) { - Write-Warning -Message "Validation failed for parameter input, available date time needs to be before the current used 'as soon as possible' deadline date and time, with a offset of 1 day"; break - } - } - } - # Validate that Deadline parameter input datetime object is in the future if the Available parameter is not passed on the command line if ($PSBoundParameters["DeadlineTime"]) { if (-not($PSBoundParameters["AvailableTime"])) {