Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AADAdministrativeUnit - fixes #4437 #4462

Merged
merged 5 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading