Skip to content

Commit

Permalink
1.4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
NickolajA committed Sep 17, 2023
1 parent 01b1fc3 commit b0f04e4
Show file tree
Hide file tree
Showing 28 changed files with 504 additions and 269 deletions.
2 changes: 1 addition & 1 deletion IntuneWin32App.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
RootModule = 'IntuneWin32App.psm1'

# Version number of this module.
ModuleVersion = '1.4.1'
ModuleVersion = '1.4.2'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down
36 changes: 21 additions & 15 deletions Private/Get-IntuneWin32AppRelationExistence.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function Get-IntuneWin32AppRelation {
function Get-IntuneWin32AppRelationshipExistence {
<#
.SYNOPSIS
Retrieve any existing supersedence and dependency (relations) configuration from an existing Win32 application.
Expand All @@ -9,30 +9,37 @@ function Get-IntuneWin32AppRelation {
.PARAMETER ID
Specify the ID for an existing Win32 application to retrieve relation configuration from.
.PARAMETER Type
Specify the type of relationship.
.NOTES
Author: Nickolaj Andersen
Contact: @NickolajA
Created: 2021-04-02
Updated: 2021-08-31
Updated: 2023-09-04
Version history:
1.0.0 - (2021-04-02) Function created
1.0.1 - (2021-08-31) Updated to use new authentication header
1.0.2 - (2023-09-04) Renamed function, was not named correctly. Added Type parameter and updated with Test-AccessToken.
#>
[CmdletBinding(SupportsShouldProcess = $true)]
param(
[parameter(Mandatory = $true, HelpMessage = "Specify the ID for an existing Win32 application to retrieve relation configuration from.")]
[ValidateNotNullOrEmpty()]
[string]$ID
[string]$ID,

[Parameter(Mandatory = $true, HelpMessage = "Specify the type of relationship.")]
[ValidateSet("Dependency", "Supersedence")]
[string]$Type
)
Begin {
# Ensure required authentication header variable exists
if ($Global:AuthenticationHeader -eq $null) {
Write-Warning -Message "Authentication token was not found, use Connect-MSIntuneGraph before using this function"; break
}
else {
$TokenLifeTime = ($Global:AuthenticationHeader.ExpiresOn - (Get-Date).ToUniversalTime()).Minutes
if ($TokenLifeTime -le 0) {
if ((Test-AccessToken) -eq $false) {
Write-Warning -Message "Existing token found but has expired, use Connect-MSIntuneGraph to request a new authentication token"; break
}
else {
Expand All @@ -46,33 +53,32 @@ function Get-IntuneWin32AppRelation {
Process {
try {
# Define static variables
$RelationExistence = $false
$RelationshipExistence = $false

# Attempt to call Graph and retrieve supersedence configuration for Win32 app
$Win32AppRelationsResponse = Invoke-IntuneGraphRequest -APIVersion "Beta" -Resource "mobileApps/$($ID)/relationships" -Method "GET" -ErrorAction Stop
$Win32AppRelationshipResponse = Invoke-IntuneGraphRequest -APIVersion "Beta" -Resource "mobileApps/$($ID)/relationships" -Method "GET" -ErrorAction "Stop"

# Switch depending on input type
if ($Win32AppRelationsResponse.value -ne $null) {
if ($Win32AppRelationshipResponse.value -ne $null) {
switch ($Type) {
"Dependency" {
if ($Win32AppRelationsResponse.value.'@odata.type' -like "#microsoft.graph.mobileAppDependency") {
$RelationExistence = $true
if ($Win32AppRelationshipResponse.value.'@odata.type' -like "#microsoft.graph.mobileAppDependency") {
$RelationshipExistence = $true
}
}
"Supersedence" {
if ($Win32AppRelationsResponse.value.'@odata.type' -like "#microsoft.graph.mobileAppSupersedence") {
$RelationExistence = $true
if ($Win32AppRelationshipResponse.value.'@odata.type' -like "#microsoft.graph.mobileAppSupersedence") {
$RelationshipExistence = $true
}
}
}
}

# Handle return value
return $RelationExistence

return $RelationshipExistence
}
catch [System.Exception] {
Write-Warning -Message "An error occurred while retrieving supersedence configuration for Win32 app: $($ID). Error message: $($_.Exception.Message)"
Write-Warning -Message "An error occurred while retrieving relationships configuration for Win32 app: $($ID). Error message: $($_.Exception.Message)"
}
}
}
5 changes: 3 additions & 2 deletions Private/Invoke-AzureADGraphRequest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ function Invoke-AzureADGraphRequest {
Author: Nickolaj Andersen
Contact: @NickolajA
Created: 2020-05-26
Updated: 2023-01-23
Updated: 2023-09-04
Version history:
1.0.0 - (2020-05-26) Function created
1.0.1 - (2023-01-23) Improved the handling of error response body depending on PSEdition
1.0.2 - (2023-09-04) Updated with correct variable referencing the stored access token, which fixes issue #108
#>
param(
[parameter(Mandatory = $true)]
Expand All @@ -34,7 +35,7 @@ function Invoke-AzureADGraphRequest {
# Call Graph API and get JSON response
switch ($Method) {
"GET" {
$GraphResponse = Invoke-RestMethod -Uri $GraphURI -Headers $Global:AuthToken -Method $Method -ErrorAction Stop -Verbose:$false
$GraphResponse = Invoke-RestMethod -Uri $GraphURI -Headers $Global:AuthenticationHeader -Method $Method -ErrorAction "Stop" -Verbose:$false
}
}

Expand Down
11 changes: 8 additions & 3 deletions Private/Invoke-AzureStorageBlobUpload.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ function Invoke-AzureStorageBlobUpload {
Author: Nickolaj Andersen
Contact: @NickolajA
Created: 2020-01-04
Updated: 2022-09-03
Updated: 2023-09-04
Version history:
1.0.0 - (2020-01-04) Function created
1.0.1 - (2020-09-20) Fixed an issue where the System.IO.BinaryReader wouldn't open a file path containing whitespaces
1.0.2 - (2021-03-15) Fixed an issue where SAS Uri renewal wasn't working correctly
1.0.3 - (2022-09-03) Added access token refresh functionality when a token is about to expire, to prevent uploads from failing due to an expire access token
1.0.4 - (2023-09-04) Updated with Test-AccessToken function
#>
param(
[parameter(Mandatory = $true)]
Expand Down Expand Up @@ -52,8 +53,12 @@ function Invoke-AzureStorageBlobUpload {

# Refresh access token if about to expire
$UTCDateTime = (Get-Date).ToUniversalTime()
$TokenExpiresMinutes = ($Global:AccessToken.ExpiresOn.DateTime - $UTCDateTime).Minutes
if ($TokenExpiresMinutes -le 10) {

# Determine the token expiration count as minutes
$TokenExpireMinutes = [System.Math]::Round(([datetime]$Global:AccessToken.ExpiresOn.ToUniversalTime().UtcDateTime - $UTCDateTime).TotalMinutes)

# Determine if refresh of access token is required when expiration count is less than or equal to minimum age
if ($TokenExpireMinutes -le 10) {
Write-Verbose -Message "Existing token found but is soon about to expire, refreshing token"
Connect-MSIntuneGraph -TenantID $Global:AccessTokenTenantID -Refresh
}
Expand Down
Loading

0 comments on commit b0f04e4

Please sign in to comment.