Skip to content

Commit

Permalink
Adding an additional property specific to MacOS Lob app 'IgnoreVersio…
Browse files Browse the repository at this point in the history
…nDetection', it's a Boolean property.
  • Loading branch information
Kajalp1079 committed Oct 3, 2024
1 parent d23f429 commit 6953462
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ function Get-TargetResource
[System.Boolean]
$IsFeatured,

[Parameter()]
[System.Boolean]
$IgnoreVersionDetection,

[Parameter()]
[System.String]
$Notes,
Expand Down Expand Up @@ -63,6 +67,7 @@ function Get-TargetResource
[Microsoft.Management.Infrastructure.CimInstance[]]
$Assignments,


#endregion

[Parameter()]
Expand Down Expand Up @@ -121,15 +126,17 @@ function Get-TargetResource
$instance = Get-MgBetaDeviceAppManagementMobileApp `
-Filter "(isof('microsoft.graph.macOSLobApp') and displayName eq '$DisplayName')" `
-ExpandProperty "categories,assignments" `
-ErrorAction SilentlyContinue
-ErrorAction SilentlyContinue | Where-Object `
-FilterScript { $_.AdditionalProperties.'@odata.type' -eq '#microsoft.graph.macOSLobApp' }

if ($null -eq $instance)
{
Write-Verbose -Message "No Mobile app with DisplayName {$DisplayName} was found. Search with DisplayName."
$instance = Get-MgBetaDeviceAppManagementMobileApp `
-MobileAppId $Id `
-ExpandProperty "categories,assignments" `
-ErrorAction Stop
-ErrorAction Stop | Where-Object `
-FilterScript { $_.AdditionalProperties.'@odata.type' -eq '#microsoft.graph.macOSLobApp' }
}

if ($null -eq $instance)
Expand All @@ -153,6 +160,7 @@ function Get-TargetResource
Publisher = $instance.Publisher
PublishingState = $instance.PublishingState.ToString()
RoleScopeTagIds = $instance.RoleScopeTagIds
IgnoreVersionDetection = $instance.AdditionalProperties.IgnoreVersionDetection

Ensure = 'Present'
Credential = $Credential
Expand Down Expand Up @@ -229,6 +237,10 @@ function Set-TargetResource
[System.Boolean]
$IsFeatured,

[Parameter()]
[System.Boolean]
$IgnoreVersionDetection,

[Parameter()]
[System.String]
$Notes,
Expand Down Expand Up @@ -262,6 +274,7 @@ function Set-TargetResource
[Microsoft.Management.Infrastructure.CimInstance[]]
$Assignments,


#endregion

[Parameter()]
Expand Down Expand Up @@ -320,6 +333,8 @@ function Set-TargetResource
$setParameters.remove('Categories') | Out-Null
$setParameters.remove('Assignments') | Out-Null

$AdditionalProperties = Get-M365DSCIntuneMobileMocOSLobAppAdditionalProperties -Properties ([System.Collections.Hashtable]$PSBoundParameters)

if($null -ne $Categories)
{
[System.Object[]]$categoriesValue = ConvertTo-M365DSCIntuneAppCategories -Categories $Categories
Expand All @@ -329,20 +344,22 @@ function Set-TargetResource
# CREATE
if ($Ensure -eq 'Present' -and $currentInstance.Ensure -eq 'Absent')
{
$app = New-MgBetaDeviceAppManagementMobileApp @setParameters
$app = New-MgBetaDeviceAppManagementMobileApp @setParameters -AdditionalProperties $AdditionalProperties

#region Assignments
$assignmentsHash = ConvertTo-IntuneMobileAppAssignment -IncludeDeviceFilter:$true -Assignments $Assignments
if ($app.id)
{
Update-MgBetaDeviceAppManagementMobileAppAssignment -MobileAppId $app.id `
-Targets $assignmentsHash `
-Repository 'deviceAppManagement/mobileAppAssignments'
}
#endregion Assignments
}
# UPDATE
elseif ($Ensure -eq 'Present' -and $currentInstance.Ensure -eq 'Present')
{
Update-MgBetaDeviceAppManagementMobileApp -MobileAppId $currentInstance.Id @setParameters
Update-MgBetaDeviceAppManagementMobileApp -MobileAppId $currentInstance.Id @setParameters -AdditionalProperties $AdditionalProperties

$assignmentsHash = ConvertTo-IntuneMobileAppAssignment -IncludeDeviceFilter:$true -Assignments $Assignments
if ($app.id)
Expand Down Expand Up @@ -391,6 +408,10 @@ function Test-TargetResource
[System.Boolean]
$IsFeatured,

[Parameter()]
[System.Boolean]
$IgnoreVersionDetection,

[Parameter()]
[System.String]
$Notes,
Expand Down Expand Up @@ -424,7 +445,6 @@ function Test-TargetResource
[Microsoft.Management.Infrastructure.CimInstance[]]
$Assignments,


#endregion

[Parameter()]
Expand Down Expand Up @@ -583,9 +603,10 @@ function Export-TargetResource
{
$Script:ExportMode = $true
[array] $Script:exportedInstances = Get-MgBetaDeviceAppManagementMobileApp `
-Filter "microsoft.graph.managedApp/appAvailability eq null" `
-Filter "isof('microsoft.graph.macOSLobApp')" `
-ExpandProperty "categories,assignments" `
-ErrorAction Stop
-ErrorAction Stop | Where-Object `
-FilterScript { $_.AdditionalProperties.'@odata.type' -eq '#microsoft.graph.macOSLobApp' }

$i = 1
$dscContent = ''
Expand Down Expand Up @@ -614,6 +635,9 @@ function Export-TargetResource
Publisher = $config.Publisher
PublishingState = $config.PublishingState.ToString()
RoleScopeTagIds = $config.RoleScopeTagIds

IgnoreVersionDetection = $config.AdditionalProperties.IgnoreVersionDetection

# LargeIcon = $config.LargeIcon
# ChildApps = $config.ChildApps

Expand Down Expand Up @@ -830,6 +854,30 @@ function Get-M365DSCIntuneAppCategoriesAsString
return $StringContent
}

function Get-M365DSCIntuneMobileMocOSLobAppAdditionalProperties
{
[CmdletBinding()]
[OutputType([System.Collections.Hashtable])]
param
(
[Parameter(Mandatory = 'true')]
[System.Collections.Hashtable]
$Properties
)

$results = @{'@odata.type' = '#microsoft.graph.macOSLobApp' }
foreach ($property in $properties.Keys)
{
if ($property -ne 'Verbose')
{
$propertyName = $property[0].ToString().ToLower() + $property.Substring(1, $property.Length - 1)
$propertyValue = $properties.$property
$results.Add($propertyName, $propertyValue)
}
}
return $results
}

#endregion Helper functions

Export-ModuleMember -Function *-TargetResource
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ class MSFT_IntuneMobileAppsMacOSLobApp : OMI_BaseResource
[Write, Description("The list of categories for this app."), EmbeddedInstance("MSFT_DeviceManagementMobileAppCategory")] String Categories[];
[Write, Description("The list of assignments for this app."), EmbeddedInstance("MSFT_DeviceManagementMobileAppAssignment")] String Assignments[];

[Write, Description("The privacy statement Url. Inherited from mobileApp.")] String BundleId;
[Write, Description("The publisher of the app. Inherited from mobileApp.")] String BuildNumber;

[Write, Description("Wether to ignore the version of the app or not.")] Boolean IgnoreVersionDetection;


[Write, Description("Present ensures the policy exists, absent ensures it is removed."), ValueMap{"Present", "Absent"}, Values{"Present", "Absent"}] String Ensure;
[Write, Description("Credentials of the Admin"), EmbeddedInstance("MSFT_Credential")] string Credential;
[Write, Description("Id of the Azure Active Directory application to authenticate with.")] String ApplicationId;
Expand Down

0 comments on commit 6953462

Please sign in to comment.