Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented AutoUpdateSupersededApps switch #175

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 30 additions & 14 deletions Public/Add-IntuneWin32AppAssignmentAllDevices.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand All @@ -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)) {
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand All @@ -206,6 +214,7 @@ function Add-IntuneWin32AppAssignmentAllDevices {
"source" = "direct"
"target" = $TargetAssignment
}

$SettingsTable = @{
"@odata.type" = "#microsoft.graph.win32LobAppAssignmentSettings"
"notifications" = $Notification
Expand All @@ -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 = @{
Expand Down
42 changes: 29 additions & 13 deletions Public/Add-IntuneWin32AppAssignmentAllUsers.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand All @@ -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
}
}

Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand All @@ -206,6 +214,7 @@ function Add-IntuneWin32AppAssignmentAllUsers {
"source" = "direct"
"target" = $TargetAssignment
}

$SettingsTable = @{
"@odata.type" = "#microsoft.graph.win32LobAppAssignmentSettings"
"notifications" = $Notification
Expand All @@ -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 = @{
Expand Down
Loading