Skip to content

Commit

Permalink
Merge pull request #5258 from ricmestre/fixappcategory
Browse files Browse the repository at this point in the history
IntuneAppCategory: Fix retrieval of resource
  • Loading branch information
NikCharlebois authored Oct 24, 2024
2 parents 2cf778a + a5b2cf4 commit 019cbf8
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 25 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
* Initial release.
* EXOTenantAllowBlockListItems
* Fixed `Test-TargetResource` to correctly mark when this resource is removed
* IntuneAppCategory
* Fixed retrieval of resource which could then result in multiple categories
being created with same name.
* IntuneDerivedCredential
* Fixed export and deployment when `NotificationType` had more than one option
selected
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,25 +78,25 @@ function Get-TargetResource

if ($null -eq $instance)
{
$instance = Get-MgBetaDeviceAppManagementMobileAppCategory -MobileAppCategoryId $Id -ErrorAction Stop

if ($null -eq $instance)
{
Write-Verbose -Message "Could not find MobileAppCategory by Id {$Id}."

if (-Not [string]::IsNullOrEmpty($DisplayName))
{
$instance = Get-MgBetaDeviceAppManagementMobileAppConfiguration `
-Filter "DisplayName eq '$DisplayName'" `
-ErrorAction SilentlyContinue
}
}

if ($null -eq $instance)
{
Write-Verbose -Message "Could not find MobileAppCategory by DisplayName {$DisplayName}."
return $nullResult
}
$instance = Get-MgBetaDeviceAppManagementMobileAppCategory -MobileAppCategoryId $Id -ErrorAction SilentlyContinue

if ($null -eq $instance)
{
Write-Verbose -Message "Could not find MobileAppCategory by Id {$Id}."

if (-Not [string]::IsNullOrEmpty($DisplayName))
{
$instance = Get-MgBetaDeviceAppManagementMobileAppCategory `
-Filter "DisplayName eq '$DisplayName'" `
-ErrorAction SilentlyContinue
}
}

if ($null -eq $instance)
{
Write-Verbose -Message "Could not find MobileAppCategory by DisplayName {$DisplayName}."
return $nullResult
}
}

$results = @{
Expand Down Expand Up @@ -192,22 +192,27 @@ function Set-TargetResource
$currentInstance = Get-TargetResource @PSBoundParameters

$setParameters = Remove-M365DSCAuthenticationParameter -BoundParameters $PSBoundParameters
$setParameters.remove('Id') | Out-Null
$setParameters.remove('Ensure') | Out-Null
$setParameters.Remove('Id') | Out-Null

# CREATE
if ($Ensure -eq 'Present' -and $currentInstance.Ensure -eq 'Absent')
{
Write-Verbose -Message "Creating an Intune App Category with DisplayName {$DisplayName}"

New-MgBetaDeviceAppManagementMobileAppCategory @SetParameters
}
# UPDATE
elseif ($Ensure -eq 'Present' -and $currentInstance.Ensure -eq 'Present')
{
Write-Verbose -Message "Updating the Intune App Category with DisplayName {$DisplayName}"

Update-MgBetaDeviceAppManagementMobileAppCategory -MobileAppCategoryId $currentInstance.Id @SetParameters
}
# REMOVE
elseif ($Ensure -eq 'Absent' -and $currentInstance.Ensure -eq 'Present')
{
Write-Verbose -Message "Removing the Intune App Category with DisplayName {$DisplayName}"

Remove-MgBetaDeviceAppManagementMobileAppCategory -MobileAppCategoryId $currentInstance.Id -Confirm:$false
}
}
Expand Down Expand Up @@ -279,13 +284,26 @@ function Test-TargetResource
$CurrentValues = Get-TargetResource @PSBoundParameters
$ValuesToCheck = ([Hashtable]$PSBoundParameters).Clone()

if ($CurrentValues.Ensure -ne $Ensure)
{
Write-Verbose -Message "Test-TargetResource returned $false"
return $false
}
$testResult = $true

$ValuesToCheck = Remove-M365DSCAuthenticationParameter -BoundParameters $ValuesToCheck
$ValuesToCheck.Remove('Id') | Out-Null

Write-Verbose -Message "Current Values: $(Convert-M365DscHashtableToString -Hashtable $CurrentValues)"
Write-Verbose -Message "Target Values: $(Convert-M365DscHashtableToString -Hashtable $ValuesToCheck)"

$testResult = Test-M365DSCParameterState -CurrentValues $CurrentValues `
-Source $($MyInvocation.MyCommand.Source) `
-DesiredValues $PSBoundParameters `
-ValuesToCheck $ValuesToCheck.Keys
if ($testResult)
{
$testResult = Test-M365DSCParameterState -CurrentValues $CurrentValues `
-Source $($MyInvocation.MyCommand.Source) `
-DesiredValues $PSBoundParameters `
-ValuesToCheck $ValuesToCheck.Keys
}

Write-Verbose -Message "Test-TargetResource returned $testResult"

Expand Down

0 comments on commit 019cbf8

Please sign in to comment.