Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ function Get-EntraDirectoryRoleAssignment {
[System.String[]] $Property
)

begin {
# Ensure connection to Microsoft Entra
if (-not (Get-EntraContext)) {
$errorMessage = "Not connected to Microsoft Graph. Use ' Connect-Entra -Scopes RoleManagement.Read.Directory, EntitlementManagement.Read.All ' to authenticate."
Write-Error -Message $errorMessage -ErrorAction Stop
return
}
}

PROCESS {
$params = @{}
$customHeaders = New-EntraCustomHeaders -Command $MyInvocation.MyCommand
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ function Get-EntraDirectoryRoleDefinition {
[Alias("Select")]
[System.String[]] $Property
)

begin {
# Ensure connection to Microsoft Entra
if (-not (Get-EntraContext)) {
$errorMessage = "Not connected to Microsoft Graph. Use 'Connect-Entra -Scopes RoleManagement.Read.Directory, EntitlementManagement.Read.All' to authenticate."
Write-Error -Message $errorMessage -ErrorAction Stop
return
}
}

PROCESS {
$params = @{}
$customHeaders = New-EntraCustomHeaders -Command $MyInvocation.MyCommand
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ function New-EntraDirectoryRoleAssignment {
[System.String] $RoleDefinitionId
)

begin {
# Ensure connection to Microsoft Entra
if (-not (Get-EntraContext)) {
$errorMessage = "Not connected to Microsoft Graph. Use 'Connect-Entra -Scopes RoleManagement.ReadWrite.Directory, EntitlementManagement.ReadWrite.All' to authenticate."
Write-Error -Message $errorMessage -ErrorAction Stop
return
}
}

PROCESS {
$params = @{}
$customHeaders = New-EntraCustomHeaders -Command $MyInvocation.MyCommand
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ function New-EntraDirectoryRoleDefinition {
[System.String] $DisplayName
)

begin {
# Ensure connection to Microsoft Entra
if (-not (Get-EntraContext)) {
$errorMessage = "Not connected to Microsoft Graph. Use 'Connect-Entra -Scopes RoleManagement.ReadWrite.Directory' to authenticate."
Write-Error -Message $errorMessage -ErrorAction Stop
return
}
}

PROCESS {
$params = @{}
$customHeaders = New-EntraCustomHeaders -Command $MyInvocation.MyCommand
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ function Remove-EntraDirectoryRoleAssignment {
[System.String] $UnifiedRoleAssignmentId
)

begin {
# Ensure connection to Microsoft Entra
if (-not (Get-EntraContext)) {
$errorMessage = "Not connected to Microsoft Graph. Use 'Connect-Entra -Scopes RoleManagement.ReadWrite.Directory, EntitlementManagement.ReadWrite.All' to authenticate."
Write-Error -Message $errorMessage -ErrorAction Stop
return
}
}

PROCESS {
$params = @{}
$customHeaders = New-EntraCustomHeaders -Command $MyInvocation.MyCommand
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ function Remove-EntraDirectoryRoleDefinition {
[System.String] $UnifiedRoleDefinitionId
)

begin {
# Ensure connection to Microsoft Entra
if (-not (Get-EntraContext)) {
$errorMessage = "Not connected to Microsoft Graph. Use 'Connect-Entra -Scopes RoleManagement.ReadWrite.Directory' to authenticate."
Write-Error -Message $errorMessage -ErrorAction Stop
return
}
}

PROCESS {
$params = @{}
$customHeaders = New-EntraCustomHeaders -Command $MyInvocation.MyCommand
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ function Set-EntraDirectoryRoleDefinition {
[System.String] $DisplayName
)

begin {
# Ensure connection to Microsoft Entra
if (-not (Get-EntraContext)) {
$errorMessage = "Not connected to Microsoft Graph. Use 'Connect-Entra -Scopes RoleManagement.ReadWrite.Directory' to authenticate."
Write-Error -Message $errorMessage -ErrorAction Stop
return
}
}

PROCESS {
$params = @{}
$customHeaders = New-EntraCustomHeaders -Command $MyInvocation.MyCommand
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ In delegated scenarios, the signed-in user must have either a supported Microsof
### Example 1: Remove a role assignment

```powershell
Connect-Entra -Scopes 'RoleManagement.ReadWrite.Directory', 'EntitlementManagement.ReadWrite.All'1
Connect-Entra -Scopes 'RoleManagement.ReadWrite.Directory', 'EntitlementManagement.ReadWrite.All'
$user = Get-EntraUser -UserId '[email protected]'
$role = Get-EntraDirectoryRoleDefinition -Filter "DisplayName eq 'Helpdesk Administrator'"
$assignment = Get-EntraDirectoryRoleAssignment -All | Where-Object { $_.principalId -eq $user.Id -AND $_.RoleDefinitionId -eq $role.Id }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ BeforeAll {
}

Mock -CommandName Get-MgRoleManagementDirectoryRoleAssignment -MockWith $scriptblock -ModuleName Microsoft.Entra.Governance

Mock -CommandName Get-EntraContext -MockWith {
@{
Environment = @{
Name = "Global"
}
Scopes = @('RoleManagement.Read.Directory', 'EntitlementManagement.Read.All')
}
} -ModuleName Microsoft.Entra.Governance
}

Describe "Get-EntraDirectoryRoleAssignment" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ BeforeAll {
}

Mock -CommandName Get-MgRoleManagementDirectoryRoleDefinition -MockWith $scriptblock -ModuleName Microsoft.Entra.Governance

Mock -CommandName Get-EntraContext -MockWith {
@{
Environment = @{
Name = "Global"
}
Scopes = @('RoleManagement.Read.Directory', 'EntitlementManagement.Read.All')
}
} -ModuleName Microsoft.Entra.Governance
}

Describe "Get-EntraDirectoryRoleDefinition" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ BeforeAll {
}

Mock -CommandName New-MgRoleManagementDirectoryRoleAssignment -MockWith $scriptblock -ModuleName Microsoft.Entra.Governance

Mock -CommandName Get-EntraContext -MockWith {
@{
Environment = @{
Name = "Global"
}
Scopes = @('RoleManagement.ReadWrite.Directory', 'EntitlementManagement.ReadWrite.All')
}
} -ModuleName Microsoft.Entra.Governance
}

Describe "New-EntraDirectoryRoleAssignment" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ BeforeAll {
}

Mock -CommandName New-MgRoleManagementDirectoryRoleDefinition -MockWith $scriptblock -ModuleName Microsoft.Entra.Governance

Mock -CommandName Get-EntraContext -MockWith {
@{
Environment = @{
Name = "Global"
}
Scopes = @('RoleManagement.ReadWrite.Directory')
}
} -ModuleName Microsoft.Entra.Governance
}

Describe "New-EntraDirectoryRoleDefinition" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ BeforeAll {
Import-Module (Join-Path $PSScriptRoot "..\..\Common-Functions.ps1") -Force

Mock -CommandName Remove-MgRoleManagementDirectoryRoleAssignment -MockWith {} -ModuleName Microsoft.Entra.Governance

Mock -CommandName Get-EntraContext -MockWith {
@{
Environment = @{
Name = "Global"
}
Scopes = @('RoleManagement.ReadWrite.Directory', 'EntitlementManagement.ReadWrite.All')
}
} -ModuleName Microsoft.Entra.Governance
}

Describe "Remove-EntraDirectoryRoleAssignment" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ BeforeAll {
Import-Module (Join-Path $PSScriptRoot "..\..\Common-Functions.ps1") -Force

Mock -CommandName Remove-MgRoleManagementDirectoryRoleDefinition -MockWith {} -ModuleName Microsoft.Entra.Governance

Mock -CommandName Get-EntraContext -MockWith {
@{
Environment = @{
Name = "Global"
}
Scopes = @('RoleManagement.ReadWrite.Directory')
}
} -ModuleName Microsoft.Entra.Governance
}

Describe "Remove-EntraDirectoryRoleDefinition" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ BeforeAll {
Import-Module (Join-Path $PSScriptRoot "..\..\Common-Functions.ps1") -Force

Mock -CommandName Update-MgRoleManagementDirectoryRoleDefinition -MockWith {} -ModuleName Microsoft.Entra.Governance

Mock -CommandName Get-EntraContext -MockWith {
@{
Environment = @{
Name = "Global"
}
Scopes = @('RoleManagement.ReadWrite.Directory')
}
} -ModuleName Microsoft.Entra.Governance
}

Describe "Set-EntraDirectoryRoleDefinition" {
Expand Down