diff --git a/Public/Add-IntuneWin32AppAssignmentAllDevices.ps1 b/Public/Add-IntuneWin32AppAssignmentAllDevices.ps1 index 02d33d2..19fcd64 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. @@ -49,13 +52,15 @@ function Add-IntuneWin32AppAssignmentAllDevices { Author: Nickolaj Andersen Contact: @NickolajA Created: 2020-09-20 - Updated: 2023-09-04 + Updated: 2024-09-03 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-09-03) Updated with autoUpdateSettings parameters + 1.0.5 - (2024-09-03) Deleted AvailableTime validation #> [CmdletBinding(SupportsShouldProcess = $true)] param( @@ -90,6 +95,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, @@ -119,7 +129,7 @@ function Add-IntuneWin32AppAssignmentAllDevices { ) Begin { # Ensure required authentication header variable exists - if ($Global:AuthenticationHeader -eq $null) { + if ($null -eq $Global:AuthenticationHeader) { Write-Warning -Message "Authentication token was not found, use Connect-MSIntuneGraph before using this function"; break } else { @@ -131,16 +141,14 @@ function Add-IntuneWin32AppAssignmentAllDevices { # Set script variable for error action preference $ErrorActionPreference = "Stop" - # 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["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 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 +183,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 +197,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 +214,7 @@ function Add-IntuneWin32AppAssignmentAllDevices { "source" = "direct" "target" = $TargetAssignment } + $SettingsTable = @{ "@odata.type" = "#microsoft.graph.win32LobAppAssignmentSettings" "notifications" = $Notification @@ -215,6 +224,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..44d4fd7 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. @@ -49,13 +52,15 @@ function Add-IntuneWin32AppAssignmentAllUsers { Author: Nickolaj Andersen Contact: @NickolajA Created: 2020-09-20 - Updated: 2023-09-04 + Updated: 2024-09-03 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-09-03) Updated with autoUpdateSettings parameters + 1.0.5 - (2024-09-03) Deleted AvailableTime validation #> [CmdletBinding(SupportsShouldProcess = $true)] param( @@ -90,6 +95,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, @@ -119,7 +129,7 @@ function Add-IntuneWin32AppAssignmentAllUsers { ) Begin { # Ensure required authentication header variable exists - if ($Global:AuthenticationHeader -eq $null) { + if ($null -eq $Global:AuthenticationHeader) { Write-Warning -Message "Authentication token was not found, use Connect-MSIntuneGraph before using this function"; break } else { @@ -131,12 +141,10 @@ function Add-IntuneWin32AppAssignmentAllUsers { # Set script variable for error action preference $ErrorActionPreference = "Stop" - # 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["AutoUpdateSupersededApps"]) { + if ($PSBoundParameters["Intent"] -ne "available") { + Write-Warning -Message "Validation failed for parameter input, AutoUpdateSupersededApps is only allowed with Intent equals available."; break } } @@ -175,9 +183,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 +197,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 +214,7 @@ function Add-IntuneWin32AppAssignmentAllUsers { "source" = "direct" "target" = $TargetAssignment } + $SettingsTable = @{ "@odata.type" = "#microsoft.graph.win32LobAppAssignmentSettings" "notifications" = $Notification @@ -215,6 +224,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 69c211a..15b1426 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-09-03 Version history: 1.0.0 - (2020-09-20) Function created @@ -67,6 +70,8 @@ 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-09-03) Updated with autoUpdateSettings parameters + 1.0.7 - (2024-09-03) Deleted AvailableTime validation #> [CmdletBinding(SupportsShouldProcess = $true)] param( @@ -114,6 +119,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, @@ -143,7 +153,7 @@ function Add-IntuneWin32AppAssignmentGroup { ) Begin { # Ensure required authentication header variable exists - if ($Global:AuthenticationHeader -eq $null) { + if ($null -eq $Global:AuthenticationHeader) { Write-Warning -Message "Authentication token was not found, use Connect-MSIntuneGraph before using this function"; break } else { @@ -155,12 +165,10 @@ function Add-IntuneWin32AppAssignmentGroup { # Set script variable for error action preference $ErrorActionPreference = "Stop" - # 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["AutoUpdateSupersededApps"]) { + if ($PSBoundParameters["Intent"] -ne "available") { + Write-Warning -Message "Validation failed for parameter input, AutoUpdateSupersededApps is only allowed with Intent equals available."; break } } @@ -214,9 +222,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 { @@ -228,7 +236,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 @@ -242,8 +250,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 } @@ -254,6 +262,7 @@ function Add-IntuneWin32AppAssignmentGroup { "source" = "direct" "target" = $TargetAssignment } + switch ($PSCmdlet.ParameterSetName) { "GroupInclude" { $SettingsTable = @{ @@ -270,6 +279,13 @@ function Add-IntuneWin32AppAssignmentGroup { } } + # 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/Samples/6-Assignments.ps1 b/Samples/6-Assignments.ps1 index 8afe583..bdc7d4e 100644 --- a/Samples/6-Assignments.ps1 +++ b/Samples/6-Assignments.ps1 @@ -19,11 +19,12 @@ Add-IntuneWin32AppAssignmentGroup @AssignmentArgs # Create a group based include assignment with additional configuration +# AutoUpdateSupersededApps only for Intent Available $AssignmentArgs = @{ "Include" = $true "ID" = $Win32AppID "GroupID" = $GroupID - "Intent" = "required" #available, uninstall + "Intent" = "available" #required, uninstall "Notification" = "hideAll" "AvailableTime" = (Get-Date).AddHours(1) "DeadlineTime" = (Get-Date).AddDays(1) @@ -32,6 +33,7 @@ $AssignmentArgs = @{ "EnableRestartGracePeriod" = $true "RestartNotificationSnooze" = 220 "Verbose" = $true + "AutoUpdateSupersededApps" = "enabled" } Add-IntuneWin32AppAssignmentGroup @AssignmentArgs @@ -61,9 +63,10 @@ Add-IntuneWin32AppAssignmentAllDevices @AssignmentArgs # Add an 'All Devices' assignment with additional configuration +# AutoUpdateSupersededApps only for Intent Available $AssignmentArgs = @{ "ID" = $Win32AppID - "Intent" = "required" #available, uninstall + "Intent" = "available" #required, uninstall "Notification" = "hideAll" "AvailableTime" = (Get-Date).AddHours(1) "DeadlineTime" = (Get-Date).AddDays(1) @@ -72,6 +75,7 @@ $AssignmentArgs = @{ "EnableRestartGracePeriod" = $true "RestartNotificationSnooze" = 220 "Verbose" = $true + "AutoUpdateSupersededApps" = "enabled" } Add-IntuneWin32AppAssignmentAllDevices @AssignmentArgs @@ -86,9 +90,10 @@ Add-IntuneWin32AppAssignmentAllUsers @AssignmentArgs # Add an 'All Users' assignment with additional configuration +# AutoUpdateSupersededApps only for Intent Available $AssignmentArgs = @{ "ID" = $Win32AppID - "Intent" = "required" #available, uninstall + "Intent" = "available" #required, uninstall "Notification" = "hideAll" "AvailableTime" = (Get-Date).AddHours(1) "DeadlineTime" = (Get-Date).AddDays(1) @@ -97,5 +102,6 @@ $AssignmentArgs = @{ "EnableRestartGracePeriod" = $true "RestartNotificationSnooze" = 220 "Verbose" = $true + "AutoUpdateSupersededApps" = "enabled" } Add-IntuneWin32AppAssignmentAllUsers @AssignmentArgs \ No newline at end of file