From f87b97ac20c07c37195c9ce9e829b63b1ec25756 Mon Sep 17 00:00:00 2001 From: Steve Mutungi <132555836+SteveMutungi254@users.noreply.github.com> Date: Mon, 28 Oct 2024 11:26:29 +0000 Subject: [PATCH 1/8] Add-EntraBetaScopedRoleMembership type fix --- .../Add-EntraBetaScopedRoleMembership.md | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/module/docs/entra-powershell-beta/Microsoft.Graph.Entra.Beta/Add-EntraBetaScopedRoleMembership.md b/module/docs/entra-powershell-beta/Microsoft.Graph.Entra.Beta/Add-EntraBetaScopedRoleMembership.md index 0abed3e38..aa2665af8 100644 --- a/module/docs/entra-powershell-beta/Microsoft.Graph.Entra.Beta/Add-EntraBetaScopedRoleMembership.md +++ b/module/docs/entra-powershell-beta/Microsoft.Graph.Entra.Beta/Add-EntraBetaScopedRoleMembership.md @@ -45,17 +45,12 @@ For delegated scenarios, the calling user needs at least the Privileged Role Adm ```powershell Connect-Entra -Scopes 'RoleManagement.ReadWrite.Directory' -$User = Get-EntraBetaUser -SearchString 'MarkWood' -$Role = Get-EntraBetaDirectoryRole -Filter "DisplayName eq ''" -$Unit = Get-EntraBetaAdministrativeUnit -Filter "DisplayName eq ''" -$RoleMember = New-Object -TypeName Microsoft.Open.AzureAD.Model.RoleMemberInfo -$RoleMember.ObjectId = $User.ObjectId -$params = @{ - AdministrativeUnitId = $Unit.ObjectId - RoleObjectId = $Role.ObjectId - RoleMemberInfo = $RoleMember -} -Add-EntraBetaScopedRoleMembership @params +$user = Get-EntraBetaUser -UserId 'SawyerM@contoso.com' +$role = Get-EntraBetaDirectoryRole -Filter "DisplayName eq 'Helpdesk Administrator'" +$administrativeUnit = Get-EntraBetaAdministrativeUnit -Filter "DisplayName eq 'Pacific Administrative Unit'" +$roleMember = New-Object -TypeName Microsoft.Open.MSGraph.Model.MsRoleMemberInfo +$roleMember.Id = $user.Id +Add-EntraBetaScopedRoleMembership -AdministrativeUnitId $administrativeUnit.Id -RoleObjectId $role.Id -RoleMemberInfo $roleMember ``` ```Output From c778fc693e385f8eea3fadcc3a1bce019a4c59f0 Mon Sep 17 00:00:00 2001 From: Steve Mutungi <132555836+SteveMutungi254@users.noreply.github.com> Date: Mon, 28 Oct 2024 13:32:41 +0000 Subject: [PATCH 2/8] Changing open type to [Microsoft.Open.MSGraph.Model.MsRoleMemberInfo] --- .../customizations/Add-EntraBetaScopedRoleMembership.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/EntraBeta/customizations/Add-EntraBetaScopedRoleMembership.ps1 b/module/EntraBeta/customizations/Add-EntraBetaScopedRoleMembership.ps1 index dfce8f5dd..86ea90a70 100644 --- a/module/EntraBeta/customizations/Add-EntraBetaScopedRoleMembership.ps1 +++ b/module/EntraBeta/customizations/Add-EntraBetaScopedRoleMembership.ps1 @@ -14,7 +14,7 @@ [Parameter(ParameterSetName = "InvokeByDynamicParameters")] [System.String] $AdministrativeUnitObjectId, [Parameter(ParameterSetName = "InvokeByDynamicParameters")] - [Microsoft.Open.AzureAD.Model.RoleMemberInfo] $RoleMemberInfo, + [Microsoft.Open.MSGraph.Model.MsRoleMemberInfo] $RoleMemberInfo, [Alias('ObjectId')] [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] [System.String] $AdministrativeUnitId From 11eb44ee49ada3f0364fc9b7357473245b863804 Mon Sep 17 00:00:00 2001 From: Steve Mutungi <132555836+SteveMutungi254@users.noreply.github.com> Date: Mon, 28 Oct 2024 13:54:35 +0000 Subject: [PATCH 3/8] Adding MsRoleMemberInfo type --- module/EntraBeta/customizations/Types.ps1 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/module/EntraBeta/customizations/Types.ps1 b/module/EntraBeta/customizations/Types.ps1 index a2ff0a981..d1bc168f7 100644 --- a/module/EntraBeta/customizations/Types.ps1 +++ b/module/EntraBeta/customizations/Types.ps1 @@ -85,5 +85,8 @@ public System.String Origin; public System.String Value; "@ +"Microsoft.Open.MSGraph.Model.MsRoleMemberInfo"=@" + public System.String Id; +"@ } From d0bc35c56ea2285895c33c71f296f0cd23c5c9a8 Mon Sep 17 00:00:00 2001 From: Steve Mutungi <132555836+SteveMutungi254@users.noreply.github.com> Date: Mon, 28 Oct 2024 14:07:41 +0000 Subject: [PATCH 4/8] Replacing ObjectId with Id --- .../customizations/Add-EntraBetaScopedRoleMembership.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/EntraBeta/customizations/Add-EntraBetaScopedRoleMembership.ps1 b/module/EntraBeta/customizations/Add-EntraBetaScopedRoleMembership.ps1 index 86ea90a70..1d5ff161c 100644 --- a/module/EntraBeta/customizations/Add-EntraBetaScopedRoleMembership.ps1 +++ b/module/EntraBeta/customizations/Add-EntraBetaScopedRoleMembership.ps1 @@ -75,7 +75,7 @@ { $TmpValue = $PSBoundParameters["RoleMemberInfo"] $Value = @{ - id = ($TmpValue).ObjectId + id = ($TmpValue).Id } | ConvertTo-Json $params["RoleMemberInfo"] = $Value } From 410970525728ae86368efa489a246f1696e448c2 Mon Sep 17 00:00:00 2001 From: Steve Mutungi <132555836+SteveMutungi254@users.noreply.github.com> Date: Mon, 28 Oct 2024 14:28:56 +0000 Subject: [PATCH 5/8] Adding missing declaration --- .../customizations/Add-EntraBetaScopedRoleMembership.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/EntraBeta/customizations/Add-EntraBetaScopedRoleMembership.ps1 b/module/EntraBeta/customizations/Add-EntraBetaScopedRoleMembership.ps1 index 1d5ff161c..39de450f0 100644 --- a/module/EntraBeta/customizations/Add-EntraBetaScopedRoleMembership.ps1 +++ b/module/EntraBeta/customizations/Add-EntraBetaScopedRoleMembership.ps1 @@ -22,7 +22,7 @@ PROCESS { $params = @{} $customHeaders = New-EntraBetaCustomHeaders -Command $MyInvocation.MyCommand - + $keysChanged = @{ObjectId = "Id"} if($null -ne $PSBoundParameters["ErrorAction"]) { $params["ErrorAction"] = $PSBoundParameters["ErrorAction"] From 5c8c0439892607d0b3e806b34f8694e8f236a0a3 Mon Sep 17 00:00:00 2001 From: Steve Mutungi <132555836+SteveMutungi254@users.noreply.github.com> Date: Tue, 29 Oct 2024 08:53:21 +0000 Subject: [PATCH 6/8] Remove variable based on reviewer comments --- .../customizations/Add-EntraBetaScopedRoleMembership.ps1 | 1 - 1 file changed, 1 deletion(-) diff --git a/module/EntraBeta/customizations/Add-EntraBetaScopedRoleMembership.ps1 b/module/EntraBeta/customizations/Add-EntraBetaScopedRoleMembership.ps1 index 39de450f0..39f57aa6d 100644 --- a/module/EntraBeta/customizations/Add-EntraBetaScopedRoleMembership.ps1 +++ b/module/EntraBeta/customizations/Add-EntraBetaScopedRoleMembership.ps1 @@ -22,7 +22,6 @@ PROCESS { $params = @{} $customHeaders = New-EntraBetaCustomHeaders -Command $MyInvocation.MyCommand - $keysChanged = @{ObjectId = "Id"} if($null -ne $PSBoundParameters["ErrorAction"]) { $params["ErrorAction"] = $PSBoundParameters["ErrorAction"] From 8ee990dd9208616a8012018069763eee158d3524 Mon Sep 17 00:00:00 2001 From: Steve Mutungi <132555836+SteveMutungi254@users.noreply.github.com> Date: Tue, 29 Oct 2024 08:57:48 +0000 Subject: [PATCH 7/8] Fix build error for missing type - Microsoft.Open.MSGraph.Model.MsRoleMemberInfo --- .../Add-EntraBetaScopedRoleMembership.Tests.ps1 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/module/EntraBeta/Add-EntraBetaScopedRoleMembership.Tests.ps1 b/test/module/EntraBeta/Add-EntraBetaScopedRoleMembership.Tests.ps1 index f02604332..98956540a 100644 --- a/test/module/EntraBeta/Add-EntraBetaScopedRoleMembership.Tests.ps1 +++ b/test/module/EntraBeta/Add-EntraBetaScopedRoleMembership.Tests.ps1 @@ -31,7 +31,7 @@ BeforeAll { Describe "Add-EntraBetaScopedRoleMembership" { Context "Test for Add-EntraBetaScopedRoleMembership" { It "Should add a user to the specified role within the specified administrative unit" { - $RoleMember = New-Object -TypeName Microsoft.Open.AzureAD.Model.RoleMemberInfo + $RoleMember = New-Object -TypeName Microsoft.Open.MSGraph.Model.MsRoleMemberInfo $RoleMember.ObjectId = "a23541ee-4fe9-4cf2-b628-102ebaef8f7e" $result = Add-EntraBetaScopedRoleMembership -AdministrativeUnitId "0e3840ee-40b6-4b72-827b-c06e1f59d2be" -RoleObjectId "135c35cd-85c2-4543-b86c-8f6dbedea4cf" -RoleMemberInfo $RoleMember $result | Should -Not -BeNullOrEmpty @@ -42,7 +42,7 @@ Describe "Add-EntraBetaScopedRoleMembership" { Should -Invoke -CommandName New-MgBetaDirectoryAdministrativeUnitScopedRoleMember -ModuleName Microsoft.Graph.Entra.Beta -Times 1 } It "Should add a user to the specified role within the specified administrative unit with alias" { - $RoleMember = New-Object -TypeName Microsoft.Open.AzureAD.Model.RoleMemberInfo + $RoleMember = New-Object -TypeName Microsoft.Open.MSGraph.Model.MsRoleMemberInfo $RoleMember.ObjectId = "a23541ee-4fe9-4cf2-b628-102ebaef8f7e" $result = Add-EntraBetaScopedRoleMembership -ObjectId "0e3840ee-40b6-4b72-827b-c06e1f59d2be" -RoleObjectId "135c35cd-85c2-4543-b86c-8f6dbedea4cf" -RoleMemberInfo $RoleMember $result | Should -Not -BeNullOrEmpty @@ -71,7 +71,7 @@ Describe "Add-EntraBetaScopedRoleMembership" { { Add-EntraBetaScopedRoleMembership -AdministrativeUnitId "0e3840ee-40b6-4b72-827b-c06e1f59d2be" -RoleMemberInfo "" } | Should -Throw "Cannot process argument transformation on parameter 'RoleMemberInfo'*" } It "Result should contain Alias properties"{ - $RoleMember = New-Object -TypeName Microsoft.Open.AzureAD.Model.RoleMemberInfo + $RoleMember = New-Object -TypeName Microsoft.Open.MSGraph.Model.MsRoleMemberInfo $RoleMember.ObjectId = "a23541ee-4fe9-4cf2-b628-102ebaef8f7e" $result = Add-EntraBetaScopedRoleMembership -AdministrativeUnitId "0e3840ee-40b6-4b72-827b-c06e1f59d2be" -RoleObjectId "135c35cd-85c2-4543-b86c-8f6dbedea4cf" -RoleMemberInfo $RoleMember $result.ObjectId | should -Be "zTVcE8KFQ0W4bI9tvt6kz-5AOA62QHJLgnvAbh9Z0r7uQTWi6U_yTLYoEC66749-U" @@ -91,7 +91,7 @@ Describe "Add-EntraBetaScopedRoleMembership" { $params.AdministrativeUnitId1 | Should -Be "0e3840ee-40b6-4b72-827b-c06e1f59d2be" } It "Should contain RoleId in parameters when passed RoleObjectId to it" { - $RoleMember = New-Object -TypeName Microsoft.Open.AzureAD.Model.RoleMemberInfo + $RoleMember = New-Object -TypeName Microsoft.Open.MSGraph.Model.MsRoleMemberInfo $RoleMember.ObjectId = "a23541ee-4fe9-4cf2-b628-102ebaef8f7e" $result = Add-EntraBetaScopedRoleMembership -AdministrativeUnitId "0e3840ee-40b6-4b72-827b-c06e1f59d2be" -RoleObjectId "135c35cd-85c2-4543-b86c-8f6dbedea4cf" -RoleMemberInfo $RoleMember @@ -101,7 +101,7 @@ Describe "Add-EntraBetaScopedRoleMembership" { It "Should contain 'User-Agent' header" { $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Add-EntraBetaScopedRoleMembership" $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Add-EntraBetaScopedRoleMembership" - $RoleMember = New-Object -TypeName Microsoft.Open.AzureAD.Model.RoleMemberInfo + $RoleMember = New-Object -TypeName Microsoft.Open.MSGraph.Model.MsRoleMemberInfo $RoleMember.ObjectId = "a23541ee-4fe9-4cf2-b628-102ebaef8f7e" Add-EntraBetaScopedRoleMembership -AdministrativeUnitId "0e3840ee-40b6-4b72-827b-c06e1f59d2be" -RoleObjectId "135c35cd-85c2-4543-b86c-8f6dbedea4cf" -RoleMemberInfo $RoleMember From 059ddf7b1fccf5e4edf94577d2409bb709738ee7 Mon Sep 17 00:00:00 2001 From: Steve Mutungi <132555836+SteveMutungi254@users.noreply.github.com> Date: Tue, 29 Oct 2024 09:39:52 +0000 Subject: [PATCH 8/8] Fixing build error - ObjectId as the course --- .../Add-EntraBetaScopedRoleMembership.Tests.ps1 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/module/EntraBeta/Add-EntraBetaScopedRoleMembership.Tests.ps1 b/test/module/EntraBeta/Add-EntraBetaScopedRoleMembership.Tests.ps1 index 98956540a..9f3bb5370 100644 --- a/test/module/EntraBeta/Add-EntraBetaScopedRoleMembership.Tests.ps1 +++ b/test/module/EntraBeta/Add-EntraBetaScopedRoleMembership.Tests.ps1 @@ -32,7 +32,7 @@ Describe "Add-EntraBetaScopedRoleMembership" { Context "Test for Add-EntraBetaScopedRoleMembership" { It "Should add a user to the specified role within the specified administrative unit" { $RoleMember = New-Object -TypeName Microsoft.Open.MSGraph.Model.MsRoleMemberInfo - $RoleMember.ObjectId = "a23541ee-4fe9-4cf2-b628-102ebaef8f7e" + $RoleMember.Id = "a23541ee-4fe9-4cf2-b628-102ebaef8f7e" $result = Add-EntraBetaScopedRoleMembership -AdministrativeUnitId "0e3840ee-40b6-4b72-827b-c06e1f59d2be" -RoleObjectId "135c35cd-85c2-4543-b86c-8f6dbedea4cf" -RoleMemberInfo $RoleMember $result | Should -Not -BeNullOrEmpty $result.Id | Should -Be "zTVcE8KFQ0W4bI9tvt6kz-5AOA62QHJLgnvAbh9Z0r7uQTWi6U_yTLYoEC66749-U" @@ -43,7 +43,7 @@ Describe "Add-EntraBetaScopedRoleMembership" { } It "Should add a user to the specified role within the specified administrative unit with alias" { $RoleMember = New-Object -TypeName Microsoft.Open.MSGraph.Model.MsRoleMemberInfo - $RoleMember.ObjectId = "a23541ee-4fe9-4cf2-b628-102ebaef8f7e" + $RoleMember.Id = "a23541ee-4fe9-4cf2-b628-102ebaef8f7e" $result = Add-EntraBetaScopedRoleMembership -ObjectId "0e3840ee-40b6-4b72-827b-c06e1f59d2be" -RoleObjectId "135c35cd-85c2-4543-b86c-8f6dbedea4cf" -RoleMemberInfo $RoleMember $result | Should -Not -BeNullOrEmpty $result.Id | Should -Be "zTVcE8KFQ0W4bI9tvt6kz-5AOA62QHJLgnvAbh9Z0r7uQTWi6U_yTLYoEC66749-U" @@ -72,7 +72,7 @@ Describe "Add-EntraBetaScopedRoleMembership" { } It "Result should contain Alias properties"{ $RoleMember = New-Object -TypeName Microsoft.Open.MSGraph.Model.MsRoleMemberInfo - $RoleMember.ObjectId = "a23541ee-4fe9-4cf2-b628-102ebaef8f7e" + $RoleMember.Id = "a23541ee-4fe9-4cf2-b628-102ebaef8f7e" $result = Add-EntraBetaScopedRoleMembership -AdministrativeUnitId "0e3840ee-40b6-4b72-827b-c06e1f59d2be" -RoleObjectId "135c35cd-85c2-4543-b86c-8f6dbedea4cf" -RoleMemberInfo $RoleMember $result.ObjectId | should -Be "zTVcE8KFQ0W4bI9tvt6kz-5AOA62QHJLgnvAbh9Z0r7uQTWi6U_yTLYoEC66749-U" $result.RoleObjectId | should -Be "cccccccc-85c2-4543-b86c-cccccccccccc" @@ -92,7 +92,7 @@ Describe "Add-EntraBetaScopedRoleMembership" { } It "Should contain RoleId in parameters when passed RoleObjectId to it" { $RoleMember = New-Object -TypeName Microsoft.Open.MSGraph.Model.MsRoleMemberInfo - $RoleMember.ObjectId = "a23541ee-4fe9-4cf2-b628-102ebaef8f7e" + $RoleMember.Id = "a23541ee-4fe9-4cf2-b628-102ebaef8f7e" $result = Add-EntraBetaScopedRoleMembership -AdministrativeUnitId "0e3840ee-40b6-4b72-827b-c06e1f59d2be" -RoleObjectId "135c35cd-85c2-4543-b86c-8f6dbedea4cf" -RoleMemberInfo $RoleMember $params = Get-Parameters -data $result.Parameters @@ -102,7 +102,7 @@ Describe "Add-EntraBetaScopedRoleMembership" { $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Add-EntraBetaScopedRoleMembership" $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Add-EntraBetaScopedRoleMembership" $RoleMember = New-Object -TypeName Microsoft.Open.MSGraph.Model.MsRoleMemberInfo - $RoleMember.ObjectId = "a23541ee-4fe9-4cf2-b628-102ebaef8f7e" + $RoleMember.Id = "a23541ee-4fe9-4cf2-b628-102ebaef8f7e" Add-EntraBetaScopedRoleMembership -AdministrativeUnitId "0e3840ee-40b6-4b72-827b-c06e1f59d2be" -RoleObjectId "135c35cd-85c2-4543-b86c-8f6dbedea4cf" -RoleMemberInfo $RoleMember