Skip to content

Commit

Permalink
Move MgBetaDirectoryAdministrativeUnit cmds to version 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Borgquite committed Dec 17, 2024
1 parent 52335bc commit c366771
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 98 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ function Get-TargetResource
}
else
{
$getValue = Get-MgBetaDirectoryAdministrativeUnit -AdministrativeUnitId $Id -ErrorAction SilentlyContinue
$getValue = Get-MgDirectoryAdministrativeUnit -AdministrativeUnitId $Id -ErrorAction SilentlyContinue
}
}

Expand All @@ -133,7 +133,7 @@ function Get-TargetResource
}
else
{
$getValue = Get-MgBetaDirectoryAdministrativeUnit -Filter "DisplayName eq '$DisplayName'" -ErrorAction Stop
$getValue = Get-MgDirectoryAdministrativeUnit -Filter "DisplayName eq '$DisplayName'" -ErrorAction Stop
}
}
}
Expand Down Expand Up @@ -180,7 +180,7 @@ function Get-TargetResource
if ($results.MembershipType -ne 'Dynamic')
{
Write-Verbose -Message "AU {$DisplayName} get Members"
[array]$auMembers = Get-MgBetaDirectoryAdministrativeUnitMember -AdministrativeUnitId $getValue.Id -All
[array]$auMembers = Get-MgDirectoryAdministrativeUnitMember -AdministrativeUnitId $getValue.Id -All
if ($auMembers.Count -gt 0)
{
Write-Verbose -Message "AU {$DisplayName} process $($auMembers.Count) members"
Expand Down Expand Up @@ -215,7 +215,7 @@ function Get-TargetResource

Write-Verbose -Message "AU {$DisplayName} get Scoped Role Members"
$ErrorActionPreference = 'Stop'
[array]$auScopedRoleMembers = Get-MgBetaDirectoryAdministrativeUnitScopedRoleMember -AdministrativeUnitId $getValue.Id -All
[array]$auScopedRoleMembers = Get-MgDirectoryAdministrativeUnitScopedRoleMember -AdministrativeUnitId $getValue.Id -All
if ($auScopedRoleMembers.Count -gt 0)
{
Write-Verbose -Message "AU {$DisplayName} process $($auScopedRoleMembers.Count) scoped role members"
Expand Down Expand Up @@ -556,25 +556,25 @@ function Set-TargetResource
#region resource generator code
Write-Verbose -Message "Creating new Administrative Unit with: $(Convert-M365DscHashtableToString -Hashtable $CreateParameters)"

$policy = New-MgBetaDirectoryAdministrativeUnit @CreateParameters
$policy = New-MgDirectoryAdministrativeUnit @CreateParameters

if ($MembershipType -ne 'Dynamic')
{
foreach ($member in $memberSpecification)
{
Write-Verbose -Message "Adding new dynamic member {$($member.Id)}"
$url = (Get-MSCloudLoginConnectionProfile -Workload MicrosoftGraph).ResourceUrl + "beta/$($member.Type)/$($member.Id)"
$url = (Get-MSCloudLoginConnectionProfile -Workload MicrosoftGraph).ResourceUrl + "v1.0/$($member.Type)/$($member.Id)"
$memberBodyParam = @{
'@odata.id' = $url
}

New-MgBetaDirectoryAdministrativeUnitMemberByRef -AdministrativeUnitId $policy.Id -BodyParameter $memberBodyParam
New-MgDirectoryAdministrativeUnitMemberByRef -AdministrativeUnitId $policy.Id -BodyParameter $memberBodyParam
}
}

foreach ($scopedRoleMember in $scopedRoleMemberSpecification)
{
New-MgBetaDirectoryAdministrativeUnitScopedRoleMember -AdministrativeUnitId $policy.Id -BodyParameter $scopedRoleMember
New-MgDirectoryAdministrativeUnitScopedRoleMember -AdministrativeUnitId $policy.Id -BodyParameter $scopedRoleMember
}


Expand Down Expand Up @@ -604,7 +604,7 @@ function Set-TargetResource
$UpdateParameters.Remove('ScopedRoleMembers') | Out-Null

#region resource generator code
Update-MgBetaDirectoryAdministrativeUnit @UpdateParameters `
Update-MgDirectoryAdministrativeUnit @UpdateParameters `
-AdministrativeUnitId $currentInstance.Id
#endregion

Expand Down Expand Up @@ -657,16 +657,16 @@ function Set-TargetResource
{
Write-Verbose -Message "AdministrativeUnit {$DisplayName} Adding member {$($diff.Identity)}, type {$($diff.Type)}"

$url = (Get-MSCloudLoginConnectionProfile -Workload MicrosoftGraph).ResourceUrl + "beta/$memberType/$($memberObject.Id)"
$url = (Get-MSCloudLoginConnectionProfile -Workload MicrosoftGraph).ResourceUrl + "v1.0/$memberType/$($memberObject.Id)"
$memberBodyParam = @{
'@odata.id' = $url
}
New-MgBetaDirectoryAdministrativeUnitMemberByRef -AdministrativeUnitId ($currentInstance.Id) -BodyParameter $memberBodyParam | Out-Null
New-MgDirectoryAdministrativeUnitMemberByRef -AdministrativeUnitId ($currentInstance.Id) -BodyParameter $memberBodyParam | Out-Null
}
else
{
Write-Verbose -Message "Administrative Unit {$DisplayName} Removing member {$($diff.Identity)}, type {$($diff.Type)}"
Remove-MgBetaDirectoryAdministrativeUnitMemberDirectoryObjectByRef -AdministrativeUnitId ($currentInstance.Id) -DirectoryObjectId ($memberObject.Id) | Out-Null
Remove-MgDirectoryAdministrativeUnitMemberDirectoryObjectByRef -AdministrativeUnitId ($currentInstance.Id) -DirectoryObjectId ($memberObject.Id) | Out-Null
}
}
}
Expand Down Expand Up @@ -770,15 +770,15 @@ function Set-TargetResource
}
}
# addition of scoped rolemember may throw if role is not supported as a scoped role
New-MgBetaDirectoryAdministrativeUnitScopedRoleMember -AdministrativeUnitId ($currentInstance.Id) -BodyParameter $scopedRoleMemberParam -ErrorAction Stop | Out-Null
New-MgDirectoryAdministrativeUnitScopedRoleMember -AdministrativeUnitId ($currentInstance.Id) -BodyParameter $scopedRoleMemberParam -ErrorAction Stop | Out-Null
}
else
{
if (-not [string]::IsNullOrEmpty($diff.Rolename))
{
Write-Verbose -Message "Removing scoped role {$($diff.RoleName)} member {$($diff.Identity)}, type {$($diff.Type)} from Administrative Unit {$DisplayName}"
$scopedRoleMemberObject = Get-MgBetaDirectoryAdministrativeUnitScopedRoleMember -AdministrativeUnitId ($currentInstance.Id) -All | Where-Object -FilterScript { $_.RoleId -eq $roleObject.Id -and $_.RoleMemberInfo.Id -eq $memberObject.Id }
Remove-MgBetaDirectoryAdministrativeUnitScopedRoleMember -AdministrativeUnitId ($currentInstance.Id) -ScopedRoleMembershipId $scopedRoleMemberObject.Id -ErrorAction Stop | Out-Null
$scopedRoleMemberObject = Get-MgDirectoryAdministrativeUnitScopedRoleMember -AdministrativeUnitId ($currentInstance.Id) -All | Where-Object -FilterScript { $_.RoleId -eq $roleObject.Id -and $_.RoleMemberInfo.Id -eq $memberObject.Id }
Remove-MgDirectoryAdministrativeUnitScopedRoleMember -AdministrativeUnitId ($currentInstance.Id) -ScopedRoleMembershipId $scopedRoleMemberObject.Id -ErrorAction Stop | Out-Null
}
}
}
Expand All @@ -787,11 +787,7 @@ function Set-TargetResource
elseif ($Ensure -eq 'Absent' -and $currentInstance.Ensure -eq 'Present')
{
Write-Verbose -Message "Removing AU {$DisplayName}"
# Workaround since Remove-MgBetaDirectoryAdministrativeUnit is not working with 2.11.1
# https://github.com/microsoftgraph/msgraph-sdk-powershell/issues/2529
$url = (Get-MSCloudLoginConnectionProfile -Workload MicrosoftGraph).ResourceUrl + "beta/administrativeUnits/$($currentInstance.Id)"
Invoke-MgGraphRequest -Method DELETE -Uri $url | Out-Null
#Remove-MgBetaDirectoryAdministrativeUnit -AdministrativeUnitId $currentInstance.Id
Remove-MgDirectoryAdministrativeUnit -AdministrativeUnitId $currentInstance.Id
}
}

Expand Down Expand Up @@ -1060,7 +1056,7 @@ function Export-TargetResource
$ExportParameters.Add('headers', @{'ConsistencyLevel' = 'Eventual' })
}

[array] $Script:exportedInstances = Get-MgBetaDirectoryAdministrativeUnit @ExportParameters
[array] $Script:exportedInstances = Get-MgDirectoryAdministrativeUnit @ExportParameters
#endregion

$i = 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,10 +335,10 @@ function Set-TargetResource
$NewManagementRoleParams.Remove('CustomRecipientWriteScope') | Out-Null
$ConnectionMode = New-M365DSCConnection -Workload 'MicrosoftGraph' `
-InboundParameters $PSBoundParameters
$adminUnit = Get-MgBetaDirectoryAdministrativeUnit -AdministrativeUnitId $RecipientAdministrativeUnitScope -ErrorAction SilentlyContinue
$adminUnit = Get-MgDirectoryAdministrativeUnit -AdministrativeUnitId $RecipientAdministrativeUnitScope -ErrorAction SilentlyContinue
if ($null -eq $adminUnit)
{
$adminUnit = Get-MgBetaDirectoryAdministrativeUnit -All | Where-Object -FilterScript { $_.DisplayName -eq $RecipientAdministrativeUnitScope }
$adminUnit = Get-MgDirectoryAdministrativeUnit -All | Where-Object -FilterScript { $_.DisplayName -eq $RecipientAdministrativeUnitScope }
}
$NewManagementRoleParams.RecipientAdministrativeUnitScope = $adminUnit.Id
}
Expand Down
22 changes: 11 additions & 11 deletions Modules/Microsoft365DSC/Dependencies/GraphCmdletPermissions.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ Get-MgBetaAgreement,Agreement.Read.All,NotSupported
Get-MgApplication,Application.Read.All,Application.Read.All
Get-MgApplicationOwner,Application.Read.All,Application.Read.All
Get-MgDevice,Device.Read.All,Device.Read.All
Get-MgBetaDirectoryAdministrativeUnitExtension,AdministrativeUnit.Read.All,AdministrativeUnit.Read.All
Get-MgBetaDirectoryAdministrativeUnitMember,AdministrativeUnit.Read.All,AdministrativeUnit.Read.All
Get-MgBetaDirectoryAdministrativeUnitScopedRoleMember,AdministrativeUnit.Read.All,AdministrativeUnit.Read.All
Get-MgDirectoryAdministrativeUnitExtension,AdministrativeUnit.Read.All,AdministrativeUnit.Read.All
Get-MgDirectoryAdministrativeUnitMember,AdministrativeUnit.Read.All,AdministrativeUnit.Read.All
Get-MgDirectoryAdministrativeUnitScopedRoleMember,AdministrativeUnit.Read.All,AdministrativeUnit.Read.All
Get-MgBetaDirectoryRole,RoleManagement.Read.Directory,RoleManagement.Read.Directory
Get-MgBetaDirectoryRoleTemplate,RoleManagement.Read.Directory,RoleManagement.Read.Directory
Get-MgDirectorySetting,Directory.Read.All,Directory.Read.All
Expand Down Expand Up @@ -44,9 +44,9 @@ Get-MgUserLicenseDetail,User.Read.All,User.Read.All
New-MgAdministrativeUnit,AdministrativeUnit.ReadWrite.All,AdministrativeUnit.ReadWrite.All
New-MgApplication,Application.ReadWrite.All,Application.ReadWrite.All
New-MgApplicationOwnerByRef,Application.ReadWrite.All,Application.ReadWrite.All
New-MgBetaDirectoryAdministrativeUnitExtension,AdministrativeUnit.ReadWrite.All,AdministrativeUnit.ReadWrite.All
New-MgBetaDirectoryAdministrativeUnitMemberByRef,AdministrativeUnit.ReadWrite.All,AdministrativeUnit.ReadWrite.All
New-MgBetaDirectoryAdministrativeUnitScopedRoleMember,AdministrativeUnit.ReadWrite.All,AdministrativeUnit.ReadWrite.All
New-MgDirectoryAdministrativeUnitExtension,AdministrativeUnit.ReadWrite.All,AdministrativeUnit.ReadWrite.All
New-MgDirectoryAdministrativeUnitMemberByRef,AdministrativeUnit.ReadWrite.All,AdministrativeUnit.ReadWrite.All
New-MgDirectoryAdministrativeUnitScopedRoleMember,AdministrativeUnit.ReadWrite.All,AdministrativeUnit.ReadWrite.All
New-MgBetaDirectoryRoleMemberByRef,RoleManagement.ReadWrite.Directory,RoleManagement.ReadWrite.Directory
New-MgDirectorySetting,Directory.ReadWrite.All,Directory.ReadWrite.All
New-MgEntitlementManagementAccessPackage,EntitlementManagement.ReadWrite.All,EntitlementManagement.ReadWrite.All
Expand All @@ -73,10 +73,10 @@ New-MgTeamChannelTab,TeamsTab.Create,TeamsTab.Create
New-MgUser,User.ReadWrite.All,User.ReadWrite.All
Remove-MgApplication,Application.ReadWrite.All,Application.ReadWrite.All
Remove-MgApplicationOwnerByRef,Application.ReadWrite.All,Application.ReadWrite.All
Remove-MgBetaDirectoryAdministrativeUnit,AdministrativeUnit.ReadWrite.All,AdministrativeUnit.ReadWrite.All
Remove-MgBetaDirectoryAdministrativeUnitExtension,AdministrativeUnit.ReadWrite.All,AdministrativeUnit.ReadWrite.All
Remove-MgBetaDirectoryAdministrativeUnitMemberByRef,AdministrativeUnit.ReadWrite.All,AdministrativeUnit.ReadWrite.All
Remove-MgBetaDirectoryAdministrativeUnitScopedRoleMember,AdministrativeUnit.ReadWrite.All,AdministrativeUnit.ReadWrite.All
Remove-MgDirectoryAdministrativeUnit,AdministrativeUnit.ReadWrite.All,AdministrativeUnit.ReadWrite.All
Remove-MgDirectoryAdministrativeUnitExtension,AdministrativeUnit.ReadWrite.All,AdministrativeUnit.ReadWrite.All
Remove-MgDirectoryAdministrativeUnitMemberByRef,AdministrativeUnit.ReadWrite.All,AdministrativeUnit.ReadWrite.All
Remove-MgDirectoryAdministrativeUnitScopedRoleMember,AdministrativeUnit.ReadWrite.All,AdministrativeUnit.ReadWrite.All
Remove-MgBetaDirectoryRoleMemberByRef,RoleManagement.ReadWrite.Directory,RoleManagement.ReadWrite.Directory
Remove-MgDirectorySetting,Directory.ReadWrite.All,Directory.ReadWrite.All
Remove-MgEntitlementManagementAccessPackage,EntitlementManagement.ReadWrite.All,EntitlementManagement.ReadWrite.All
Expand All @@ -101,7 +101,7 @@ Set-MgGroupLicense,Group.ReadWrite.All,Group.ReadWrite.All
Set-MgUserLicense,User.ReadWrite.All,User.ReadWrite.All
Update-MgAdministrativeUnit,AdministrativeUnit.ReadWrite.All,AdministrativeUnit.ReadWrite.All
Update-MgApplication,Application.ReadWrite.All,Application.ReadWrite.All
Update-MgBetaDirectoryAdministrativeUnitExtension,AdministrativeUnit.ReadWrite.All,AdministrativeUnit.ReadWrite.All
Update-MgDirectoryAdministrativeUnitExtension,AdministrativeUnit.ReadWrite.All,AdministrativeUnit.ReadWrite.All
Update-MgDirectorySetting,Directory.ReadWrite.All,Directory.ReadWrite.All
Update-MgBetaEntitlementManagementAccessPackage,EntitlementManagement.ReadWrite.All,EntitlementManagement.ReadWrite.All
Update-MgBetaEntitlementManagementAccessPackageCatalog,EntitlementManagement.ReadWrite.All,EntitlementManagement.ReadWrite.All
Expand Down
Loading

0 comments on commit c366771

Please sign in to comment.