Skip to content

Commit 852555a

Browse files
givinalisGivinalis Omachar
andauthored
356 - Added Authentication checks for cmdlets under DirectoryManagement submodule for Entra (#1538)
* feat: added check to all Directory Management cmdlets * test: added Get-EntraContext to the directory management tests * test: added disconnected scenario --------- Co-authored-by: Givinalis Omachar <giomachar@microsoft.com>
1 parent 7215c81 commit 852555a

137 files changed

Lines changed: 1334 additions & 11 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

module/Entra/Microsoft.Entra/DirectoryManagement/Add-EntraAdministrativeUnitMember.ps1

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ function Add-EntraAdministrativeUnitMember {
1414
[System.String] $AdministrativeUnitId
1515
)
1616

17+
begin {
18+
# Ensure connection to Microsoft Entra
19+
if (-not (Get-EntraContext)) {
20+
$errorMessage = "Not connected to Microsoft Graph. Use 'Connect-Entra -Scopes AdministrativeUnit.ReadWrite.All' to authenticate."
21+
Write-Error -Message $errorMessage -ErrorAction Stop
22+
return
23+
}
24+
}
25+
1726
PROCESS {
1827
$params = @{}
1928
$customHeaders = New-EntraCustomHeaders -Command $MyInvocation.MyCommand

module/Entra/Microsoft.Entra/DirectoryManagement/Add-EntraCustomSecurityAttributeDefinitionAllowedValue.ps1

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ function Add-EntraCustomSecurityAttributeDefinitionAllowedValue {
1313
[System.String] $CustomSecurityAttributeDefinitionId
1414
)
1515

16+
begin {
17+
# Ensure connection to Microsoft Entra
18+
if (-not (Get-EntraContext)) {
19+
$errorMessage = "Not connected to Microsoft Graph. Use 'Connect-Entra -Scopes CustomSecAttributeDefinition.ReadWrite.All' to authenticate."
20+
Write-Error -Message $errorMessage -ErrorAction Stop
21+
return
22+
}
23+
}
24+
1625
PROCESS {
1726
$params = @{}
1827
$body = @{}

module/Entra/Microsoft.Entra/DirectoryManagement/Add-EntraDeviceRegisteredOwner.ps1

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ function Add-EntraDeviceRegisteredOwner {
1414
[System.String] $OwnerId
1515
)
1616

17+
begin {
18+
# Ensure connection to Microsoft Entra
19+
if (-not (Get-EntraContext)) {
20+
$errorMessage = "Not connected to Microsoft Graph. Use 'Connect-Entra -Scopes Directory.AccessAsUser.All' to authenticate."
21+
Write-Error -Message $errorMessage -ErrorAction Stop
22+
return
23+
}
24+
}
25+
1726
PROCESS {
1827
$params = @{}
1928
$customHeaders = New-EntraCustomHeaders -Command $MyInvocation.MyCommand

module/Entra/Microsoft.Entra/DirectoryManagement/Add-EntraDeviceRegisteredUser.ps1

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ function Add-EntraDeviceRegisteredUser {
1414
[System.String] $UserId
1515
)
1616

17+
begin {
18+
# Ensure connection to Microsoft Entra
19+
if (-not (Get-EntraContext)) {
20+
$errorMessage = "Not connected to Microsoft Graph. Use 'Connect-Entra -Scopes Device.AccessAsUser.All' to authenticate."
21+
Write-Error -Message $errorMessage -ErrorAction Stop
22+
return
23+
}
24+
}
25+
1726
PROCESS {
1827
$params = @{}
1928
$customHeaders = New-EntraCustomHeaders -Command $MyInvocation.MyCommand

module/Entra/Microsoft.Entra/DirectoryManagement/Add-EntraScopedRoleMembership.ps1

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ function Add-EntraScopedRoleMembership {
1414
[Microsoft.Open.MSGraph.Model.MsRoleMemberInfo] $RoleMemberInfo
1515
)
1616

17+
begin {
18+
# Ensure connection to Microsoft Entra
19+
if (-not (Get-EntraContext)) {
20+
$errorMessage = "Not connected to Microsoft Graph. Use 'Connect-Entra -Scopes RoleManagement.ReadWrite.Directory' to authenticate."
21+
Write-Error -Message $errorMessage -ErrorAction Stop
22+
return
23+
}
24+
}
25+
1726
PROCESS {
1827
$params = @{}
1928
$body = @{}

module/Entra/Microsoft.Entra/DirectoryManagement/Confirm-EntraDomain.ps1

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ function Confirm-EntraDomain {
1313
[Microsoft.Open.AzureAD.Model.CrossCloudVerificationCodeBody] $CrossCloudVerificationCode
1414
)
1515

16+
begin {
17+
# Ensure connection to Microsoft Entra
18+
if (-not (Get-EntraContext)) {
19+
$errorMessage = "Not connected to Microsoft Graph. Use 'Connect-Entra -Scopes Domain.ReadWrite.All' to authenticate."
20+
Write-Error -Message $errorMessage -ErrorAction Stop
21+
return
22+
}
23+
}
24+
1625
PROCESS {
1726
$params = @{}
1827
$customHeaders = New-EntraCustomHeaders -Command $MyInvocation.MyCommand

module/Entra/Microsoft.Entra/DirectoryManagement/Enable-EntraDirectoryRole.ps1

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@ function Enable-EntraDirectoryRole {
1111
[System.String] $RoleTemplateId
1212
)
1313

14+
begin {
15+
# Ensure connection to Microsoft Entra
16+
if (-not (Get-EntraContext)) {
17+
$errorMessage = "Not connected to Microsoft Graph. Use 'Connect-Entra -Scopes RoleManagement.ReadWrite.Directory' to authenticate."
18+
Write-Error -Message $errorMessage -ErrorAction Stop
19+
return
20+
}
21+
}
22+
1423
PROCESS {
1524
$params = @{}
1625
$customHeaders = New-EntraCustomHeaders -Command $MyInvocation.MyCommand

module/Entra/Microsoft.Entra/DirectoryManagement/Get-EntraAccountSku.ps1

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ function Get-EntraAccountSku {
1010
[System.Guid] $TenantId
1111
)
1212

13+
begin {
14+
# Ensure connection to Microsoft Entra
15+
if (-not (Get-EntraContext)) {
16+
$errorMessage = "Not connected to Microsoft Graph. Use 'Connect-Entra -Scopes Organization.Read.All, LicenseAssignment.Read.All' to authenticate."
17+
Write-Error -Message $errorMessage -ErrorAction Stop
18+
return
19+
}
20+
}
21+
1322
PROCESS {
1423
$params = @{}
1524
$customHeaders = New-EntraCustomHeaders -Command $MyInvocation.MyCommand

module/Entra/Microsoft.Entra/DirectoryManagement/Get-EntraAdministrativeUnit.ps1

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@ function Get-EntraAdministrativeUnit {
1717
[System.String] $Filter
1818
)
1919

20+
begin {
21+
# Ensure connection to Microsoft Entra
22+
if (-not (Get-EntraContext)) {
23+
$errorMessage = "Not connected to Microsoft Graph. Use 'Connect-Entra -Scopes AdministrativeUnit.Read.All' to authenticate."
24+
Write-Error -Message $errorMessage -ErrorAction Stop
25+
return
26+
}
27+
}
28+
2029
PROCESS {
2130
$params = @{}
2231
$customHeaders = New-EntraCustomHeaders -Command $MyInvocation.MyCommand

module/Entra/Microsoft.Entra/DirectoryManagement/Get-EntraAdministrativeUnitMember.ps1

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@ function Get-EntraAdministrativeUnitMember {
1515
[switch] $All
1616
)
1717

18+
begin {
19+
# Ensure connection to Microsoft Entra
20+
if (-not (Get-EntraContext)) {
21+
$errorMessage = "Not connected to Microsoft Graph. Use 'Connect-Entra -Scopes AdministrativeUnit.ReadWrite.All' to authenticate."
22+
Write-Error -Message $errorMessage -ErrorAction Stop
23+
return
24+
}
25+
}
26+
1827
PROCESS {
1928
$params = @{}
2029
$topCount = $null

0 commit comments

Comments
 (0)