Skip to content

Commit

Permalink
Merge pull request #3790 from swisscom/fix/IntuneRoleAssignment-Defin…
Browse files Browse the repository at this point in the history
…ition-Beta

Fix IntuneRoleAssignment missing use of Beta Graph module #3590
  • Loading branch information
NikCharlebois authored Oct 17, 2023
2 parents 932de0e + d2cac33 commit 21b4410
Show file tree
Hide file tree
Showing 3 changed files with 235 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ function Get-TargetResource
$getValue = $null
if ($Id -match '^[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}$')
{
$getValue = Get-MgDeviceManagementRoleAssignment -DeviceAndAppManagementRoleAssignmentId $id -ErrorAction SilentlyContinue
$getValue = Get-MgBetaDeviceManagementRoleAssignment -DeviceAndAppManagementRoleAssignmentId $id -ErrorAction SilentlyContinue
if ($null -ne $getValue)
{
Write-Verbose -Message "Found something with id {$id}"
Expand All @@ -113,7 +113,7 @@ function Get-TargetResource
{
Write-Verbose -Message "Nothing with id {$id} was found"
$Filter = "displayName eq '$DisplayName'"
$getValue = Get-MgDeviceManagementRoleAssignment -Filter $Filter -ErrorAction SilentlyContinue
$getValue = Get-MgBetaDeviceManagementRoleAssignment -Filter $Filter -ErrorAction SilentlyContinue
if ($null -ne $getValue)
{
Write-Verbose -Message "Found something with displayname {$DisplayName}"
Expand Down Expand Up @@ -386,7 +386,7 @@ function Set-TargetResource
'@odata.type' = '#microsoft.graph.deviceAndAppManagementRoleAssignment'
'[email protected]' = "https://graph.microsoft.com/beta/deviceManagement/roleDefinitions('$roleDefinition')"
}
$policy = New-MgDeviceManagementRoleAssignment -BodyParameter $CreateParameters
$policy = New-MgBetaDeviceManagementRoleAssignment -BodyParameter $CreateParameters

}
elseif ($Ensure -eq 'Present' -and $currentInstance.Ensure -eq 'Present')
Expand All @@ -403,14 +403,14 @@ function Set-TargetResource
'[email protected]' = "https://graph.microsoft.com/beta/deviceManagement/roleDefinitions('$roleDefinition')"
}

Update-MgDeviceManagementRoleAssignment -BodyParameter $UpdateParameters `
Update-MgBetaDeviceManagementRoleAssignment -BodyParameter $UpdateParameters `
-DeviceAndAppManagementRoleAssignmentId $currentInstance.Id

}
elseif ($Ensure -eq 'Absent' -and $currentInstance.Ensure -eq 'Present')
{
Write-Verbose -Message "Removing {$DisplayName}"
Remove-MgDeviceManagementRoleAssignment -DeviceAndAppManagementRoleAssignmentId $currentInstance.Id
Remove-MgBetaDeviceManagementRoleAssignment -DeviceAndAppManagementRoleAssignmentId $currentInstance.Id
}
}

Expand Down Expand Up @@ -644,15 +644,15 @@ function Export-TargetResource

try
{
[array]$getValue = Get-MgDeviceManagementRoleAssignment `
[array]$getValue = Get-MgBetaDeviceManagementRoleAssignment `
-ErrorAction Stop | Where-Object `
-FilterScript { `
$_.AdditionalProperties.'@odata.type' -eq '#microsoft.graph.deviceAndAppManagementRoleAssignment' `
}

if (-not $getValue)
{
[array]$getValue = Get-MgDeviceManagementRoleAssignment `
[array]$getValue = Get-MgBetaDeviceManagementRoleAssignment `
-ErrorAction Stop
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
Mock -CommandName Remove-PSSession -MockWith {
}

Mock -CommandName Update-MgDeviceManagementRoleAssignment -MockWith {
Mock -CommandName Update-MgBetaDeviceManagementRoleAssignment -MockWith {
}

Mock -CommandName New-MgDeviceManagementRoleAssignment -MockWith {
Mock -CommandName New-MgBetaDeviceManagementRoleAssignment -MockWith {
}

Mock -CommandName Remove-MgDeviceManagementRoleAssignment -MockWith {
Mock -CommandName Remove-MgBetaDeviceManagementRoleAssignment -MockWith {
}

Mock -CommandName New-M365DSCConnection -MockWith {
Expand Down Expand Up @@ -68,7 +68,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
Credential = $Credential
}

Mock -CommandName Get-MgDeviceManagementRoleAssignment -MockWith {
Mock -CommandName Get-MgBetaDeviceManagementRoleAssignment -MockWith {
return $null
}
}
Expand All @@ -80,7 +80,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
}
It 'Should Create the group from the Set method' {
Set-TargetResource @testParams
Should -Invoke -CommandName New-MgDeviceManagementRoleAssignment -Exactly 1
Should -Invoke -CommandName New-MgBetaDeviceManagementRoleAssignment -Exactly 1
}
}

Expand All @@ -98,7 +98,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
Credential = $Credential
}

Mock -CommandName Get-MgDeviceManagementRoleAssignment -MockWith {
Mock -CommandName Get-MgBetaDeviceManagementRoleAssignment -MockWith {
return @{
Description = 'FakeStringValue'
DisplayName = 'FakeStringValue'
Expand Down Expand Up @@ -130,7 +130,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {

It 'Should Remove the group from the Set method' {
Set-TargetResource @testParams
Should -Invoke -CommandName Remove-MgDeviceManagementRoleAssignment -Exactly 1
Should -Invoke -CommandName Remove-MgBetaDeviceManagementRoleAssignment -Exactly 1
}
}
Context -Name 'The IntuneRoleAssignment Exists and Values are already in the desired state' -Fixture {
Expand All @@ -147,7 +147,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
Credential = $Credential
}

Mock -CommandName Get-MgDeviceManagementRoleAssignment -MockWith {
Mock -CommandName Get-MgBetaDeviceManagementRoleAssignment -MockWith {
return @{
Description = 'FakeStringValue'
DisplayName = 'FakeStringValue'
Expand Down Expand Up @@ -192,7 +192,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
Credential = $Credential
}

Mock -CommandName Get-MgDeviceManagementRoleAssignment -MockWith {
Mock -CommandName Get-MgBetaDeviceManagementRoleAssignment -MockWith {
return @{
AdditionalProperties = @{
'@odata.type' = '#microsoft.graph.'
Expand Down Expand Up @@ -229,7 +229,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {

It 'Should call the Set method' {
Set-TargetResource @testParams
Should -Invoke -CommandName Update-MgDeviceManagementRoleAssignment -Exactly 1
Should -Invoke -CommandName Update-MgBetaDeviceManagementRoleAssignment -Exactly 1
}
}

Expand All @@ -241,7 +241,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
Credential = $Credential
}

Mock -CommandName Get-MgDeviceManagementRoleAssignment -MockWith {
Mock -CommandName Get-MgBetaDeviceManagementRoleAssignment -MockWith {
return @{
Description = 'FakeStringValue'
DisplayName = 'FakeStringValue'
Expand Down
Loading

0 comments on commit 21b4410

Please sign in to comment.