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
@@ -0,0 +1,50 @@
function Get-EntraAuthorizationPolicy {
[CmdletBinding(DefaultParameterSetName = '')]
param (
[Parameter(Mandatory = $false, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[System.String] $Id,
[Parameter(Mandatory = $false, ValueFromPipeline = $false, ValueFromPipelineByPropertyName = $true)]
[System.String[]] $Property
)

PROCESS {
$params = @{}
$customHeaders = New-EntraCustomHeaders -Command $MyInvocation.MyCommand
$params["Uri"] = "https://graph.microsoft.com/v1.0/policies/authorizationPolicy?"
$params["Method"] = "GET"

if($null -ne $PSBoundParameters["Id"])
{
$Id = $Id.Substring(0, 1).ToLower() + $Id.Substring(1)
$Filter = "Id eq '$Id'"
$f = '$' + 'Filter'
$params["Uri"] += "&$f=$Filter"
}
if($null -ne $PSBoundParameters["Property"])
{
$selectProperties = $PSBoundParameters["Property"]
$selectProperties = $selectProperties -Join ','
$properties = "`$select=$($selectProperties)"
$params["Uri"] += "&$properties"
}

Write-Debug("============================ TRANSFORMATIONS ============================")
$params.Keys | ForEach-Object {"$_ : $($params[$_])" } | Write-Debug
Write-Debug("=========================================================================`n")

$response = Invoke-GraphRequest @params -Headers $customHeaders | ConvertTo-Json | ConvertFrom-Json
if($response){
$policyList = @()
foreach ($data in $response) {
$policyType = New-Object Microsoft.Graph.PowerShell.Models.MicrosoftGraphAuthorizationPolicy
$data.PSObject.Properties | ForEach-Object {
$propertyName = $_.Name
$propertyValue = $_.Value
$policyType | Add-Member -MemberType NoteProperty -Name $propertyName -Value $propertyValue -Force
}
$policyList += $policyType
}
$policyList
}
}
}
79 changes: 0 additions & 79 deletions module/Entra/customizations/Get-EntraAuthorizationPolicy.ps1

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ Connect-Entra -Scopes 'Policy.Read.All'
Get-EntraAuthorizationPolicy
```

```Output
DeletedDateTime Description DisplayName Id AllowEmailVerifiedUsersToJoinOrganization AllowI
nvites
From
--------------- ----------- ----------- -- ----------------------------------------- ------
Used to manage authorization related settings across the company. Authorization Policy authorizationPolicy True every…
```

This example gets the Microsoft Entra ID authorization policy.

### Example 2: Get an authorization policy by ID

```powershell
Expand All @@ -61,23 +71,21 @@ Get-EntraAuthorizationPolicy -Id 'authorizationPolicy' | Format-List
```

```Output
DefaultUserRolePermissions : @{AllowedToCreateApps=True; AllowedToCreateSecurityGroups=True; AllowedToCreateTenants=True; AllowedToReadBitlockerKeysForOwnedDevice=True; AllowedToReadOtherUsers=True; AdditionalProperties=}
AllowEmailVerifiedUsersToJoinOrganization : False
AllowInvitesFrom : everyone
AllowUserConsentForRiskyApps :
AllowedToSignUpEmailBasedSubscriptions : True
AllowedToUseSspr : True
BlockMsolPowerShell : False
DefaultUserRoleOverrides :
DeletedDateTime :
Description : Used to manage authorization related settings across the company.
DisplayName : Authorization Policy
EnabledPreviewFeatures : {}
GuestUserRoleId : 10dae51f-b6af-4016-8d66-8c2a99b929b3
Id : authorizationPolicy
PermissionGrantPolicyIdsAssignedToDefaultUserRole : {ManagePermissionGrantsForSelf.microsoft-user-default-legacy, ManagePermissionGrantsForOwnedResource.microsoft-dynamically-managed-permissions-for-team,
ManagePermissionGrantsForOwnedResource.microsoft-dynamically-managed-permissions-for-chat}
AdditionalProperties : {}
allowInvitesFrom : everyone
allowUserConsentForRiskyApps :
id : authorizationPolicy
defaultUserRolePermissions : @{allowedToCreateSecurityGroups=True; allowedToReadBitlockerKeysForOwnedDevice=True; allowedToCreateTenants=True;
allowedToReadOtherUsers=True; allowedToCreateApps=False; permissionGrantPoliciesAssigned=System.Object[]}
blockMsolPowerShell : False
guestUserRoleId : a0b1b346-4d3e-4e8b-98f8-753987be4970
displayName : Authorization Policy
@odata.context : https://graph.microsoft.com/v1.0/$metadata#policies/authorizationPolicy/$entity
allowedToSignUpEmailBasedSubscriptions : True
description : Used to manage authorization related settings across the company.
allowEmailVerifiedUsersToJoinOrganization : True
allowedToUseSSPR : True
DeletedDateTime :
AdditionalProperties : {}
```

This example gets the Microsoft Entra ID authorization policy.
Expand Down
21 changes: 17 additions & 4 deletions test/module/Entra/Get-EntraAuthorizationPolicy.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ BeforeAll {
)
}

Mock -CommandName Get-MgPolicyAuthorizationPolicy -MockWith $scriptblock -ModuleName Microsoft.Graph.Entra
Mock -CommandName Invoke-GraphRequest -MockWith $scriptblock -ModuleName Microsoft.Graph.Entra
}

Describe "Get-EntraAuthorizationPolicy" {
Expand All @@ -48,14 +48,27 @@ Describe "Get-EntraAuthorizationPolicy" {
$result.AllowedToUseSspr | should -Be $True
$result.BlockMsolPowerShell | should -Be $True

Should -Invoke -CommandName Get-MgPolicyAuthorizationPolicy -ModuleName Microsoft.Graph.Entra -Times 1
Should -Invoke -CommandName Invoke-GraphRequest -ModuleName Microsoft.Graph.Entra -Times 1
}
It "Should return AuthorizationPolicy when passed Id" {
$result = Get-EntraAuthorizationPolicy -Id 'authorizationPolicy'
$result | Should -Not -BeNullOrEmpty
$result.Id | should -Be 'authorizationPolicy'

Should -Invoke -CommandName Invoke-GraphRequest -ModuleName Microsoft.Graph.Entra -Times 1
}
It "Should fail when Id is invalid" {
{Get-EntraAuthorizationPolicy -Id ''} | Should -Throw 'Exception calling "Substring" with "2" argument*'
}
It "Should fail when Id is invalid" {
{Get-EntraAuthorizationPolicy -Id } | Should -Throw "Missing an argument for parameter 'Id'*"
}
It "Property parameter should work" {
$result = Get-EntraAuthorizationPolicy -Property DisplayName
$result | Should -Not -BeNullOrEmpty
$result.DisplayName | Should -Be 'AuthorizationPolicy'

Should -Invoke -CommandName Get-MgPolicyAuthorizationPolicy -ModuleName Microsoft.Graph.Entra -Times 1
Should -Invoke -CommandName Invoke-GraphRequest -ModuleName Microsoft.Graph.Entra -Times 1
}
It "Should fail when Property is empty" {
{ Get-EntraAuthorizationPolicy -Property } | Should -Throw "Missing an argument for parameter 'Property'*"
Expand All @@ -67,7 +80,7 @@ Describe "Get-EntraAuthorizationPolicy" {

$userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraAuthorizationPolicy"

Should -Invoke -CommandName Get-MgPolicyAuthorizationPolicy -ModuleName Microsoft.Graph.Entra -Times 1 -ParameterFilter {
Should -Invoke -CommandName Invoke-GraphRequest -ModuleName Microsoft.Graph.Entra -Times 1 -ParameterFilter {
$Headers.'User-Agent' | Should -Be $userAgentHeaderValue
$true
}
Expand Down