Skip to content

Commit

Permalink
Merge pull request #4462 from salbeck-sit/AADAdministrativeUnit
Browse files Browse the repository at this point in the history
AADAdministrativeUnit - fixes #4437
  • Loading branch information
NikCharlebois authored Mar 21, 2024
2 parents 0aa07e1 + dadbf0b commit 21cbec1
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 18 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

* All resources
* Fix issue where Ensure cannot be left as default 'Present'
* AADAdministrativeUnit
* Fix issue with omitted Ensure and/or Id
FIXES [#4437](https://github.com/microsoft/Microsoft365DSC/issues/4437)
* AADConditionalAccessPolicy
* Fixed schema file
* EXOCalendarProcessing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,22 +100,6 @@ function Get-TargetResource
$nullResult.Ensure = 'Absent'
try
{
$getValue = $null

#region resource generator code
if (-Not [string]::IsNullOrEmpty($Id))
{
$getValue = Get-MgBetaDirectoryAdministrativeUnit -AdministrativeUnitId $Id -ErrorAction Stop
}

if (-not $getValue -and -Not [string]::IsNullOrEmpty($DisplayName))
{
$getValue = Get-MgBetaDirectoryAdministrativeUnit -Filter "DisplayName eq '$DisplayName'" -ErrorAction Stop
}
#endregion

$nullResult = $PSBoundParameters
$nullResult.Ensure = 'Absent'

$getValue = $null
#region resource generator code
Expand Down Expand Up @@ -388,7 +372,6 @@ function Set-TargetResource
$PSBoundParameters.Remove('TenantId') | Out-Null
$PSBoundParameters.Remove('CertificateThumbprint') | Out-Null
$PSBoundParameters.Remove('ManagedIdentity') | Out-Null
$PSBoundParameters.Remove('Verbose') | Out-Null

$backCurrentMembers = $currentInstance.Members
$backCurrentScopedRoleMembers = $currentInstance.ScopedRoleMembers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
It 'Should return Values from the Get method' {
(Get-TargetResource @testParams).Ensure | Should -Be 'Present'
}

It 'Should return false from the Test method' {
Test-TargetResource @testParams | Should -Be $false
}
Expand All @@ -161,6 +161,39 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
Should -Invoke -CommandName Invoke-MgGraphRequest -Exactly 1
}
}

Context -Name 'The AU exists and values are already in desired state - without ID/Ensure' -Fixture {
BeforeAll {
$testParams = @{
Description = 'FakeStringValue2'
DisplayName = 'FakeStringValue2'
Credential = $Credential
}

Mock -CommandName Get-MgBetaDirectoryAdministrativeUnit -MockWith {
return @{
Description = 'FakeStringValue2'
DisplayName = 'FakeStringValue2'
Id = 'FakeStringValue2'
}
}
Mock -CommandName Get-MgBetaDirectoryAdministrativeUnitMember -MockWith {
return $null
}
Mock -CommandName Get-MgBetaDirectoryAdministrativeUnitScopedRoleMember -MockWith {
return $null
}
}

It 'Should return Values from the Get method' {
(Get-TargetResource @testParams).Ensure | Should -Be 'Present'
}

It 'Should return true from the Test method' {
Test-TargetResource @testParams | Should -Be $true
}
}

Context -Name 'The AU Exists and Values are already in the desired state' -Fixture {
BeforeAll {
$testParams = @{
Expand Down

0 comments on commit 21cbec1

Please sign in to comment.