|
3 | 3 | # Licensed under the MIT License. See License in the project root for license information. |
4 | 4 | # ------------------------------------------------------------------------------ |
5 | 5 | function Add-EntraServicePrincipalDelegatedPermissionClassification { |
6 | | - [CmdletBinding(DefaultParameterSetName = 'InvokeByDynamicParameters')] |
7 | | - param ( |
| 6 | + [CmdletBinding(DefaultParameterSetName = 'ByServicePrincipalAndPermissionInfo')] |
| 7 | + param ( |
| 8 | + [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Unique ID of the service principal object (Service Principal Object ID).")] |
| 9 | + [Alias('ObjectId')] |
| 10 | + [ValidateNotNullOrEmpty()] |
| 11 | + [guid] $ServicePrincipalId, |
8 | 12 |
|
9 | | - [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] |
10 | | - [System.String] $ServicePrincipalId, |
| 13 | + [Parameter(ParameterSetName = "ByServicePrincipalAndPermissionInfo", Mandatory = $true, HelpMessage = "Permission classification. e.g. Low, Medium, High")] |
| 14 | + [ValidateNotNullOrEmpty()] |
| 15 | + [System.Nullable`1[Microsoft.Open.MSGraph.Model.DelegatedPermissionClassification+ClassificationEnum]] $Classification, |
11 | 16 |
|
12 | | - [Parameter(ParameterSetName = "InvokeByDynamicParameters", Mandatory = $true)] |
13 | | - [System.Nullable`1[Microsoft.Open.MSGraph.Model.DelegatedPermissionClassification+ClassificationEnum]] $Classification, |
| 17 | + [Parameter(ParameterSetName = "ByServicePrincipalAndPermissionInfo", Mandatory = $true, HelpMessage = "Unique ID of the permission. e.g. 00000000-0000-0000-0000-000000000000")] |
| 18 | + [ValidateNotNullOrEmpty()] |
| 19 | + [guid] $PermissionId, |
14 | 20 |
|
15 | | - [Parameter(ParameterSetName = "InvokeByDynamicParameters", Mandatory = $true)] |
16 | | - [System.String] $PermissionId, |
17 | | - |
18 | | - [Parameter(ParameterSetName = "InvokeByDynamicParameters", Mandatory = $true)] |
19 | | - [System.String] $PermissionName |
| 21 | + [Parameter(ParameterSetName = "ByServicePrincipalAndPermissionInfo", Mandatory = $true, HelpMessage = "Name of the permission. e.g. HR.Read.All")] |
| 22 | + [ValidateNotNullOrEmpty()] |
| 23 | + [System.String] $PermissionName |
20 | 24 | ) |
21 | 25 |
|
| 26 | + begin { |
| 27 | + # Ensure connection to Microsoft Entra |
| 28 | + if (-not (Get-EntraContext)) { |
| 29 | + $errorMessage = "Not connected to Microsoft Graph. Use 'Connect-Entra -Scopes Policy.ReadWrite.PermissionGrant' to authenticate." |
| 30 | + Write-Error -Message $errorMessage -ErrorAction Stop |
| 31 | + return |
| 32 | + } |
| 33 | + } |
| 34 | + |
22 | 35 | PROCESS { |
23 | | - $params = @{} |
24 | | - $customHeaders = New-EntraCustomHeaders -Command $MyInvocation.MyCommand |
| 36 | + $params = @{} |
| 37 | + $customHeaders = New-EntraCustomHeaders -Command $MyInvocation.MyCommand |
25 | 38 |
|
26 | | - if ($null -ne $PSBoundParameters["ServicePrincipalId"]) |
27 | | - { |
28 | | - $params["ServicePrincipalId"] = $PSBoundParameters["ServicePrincipalId"] |
29 | | - } |
30 | | - if($PSBoundParameters.ContainsKey("Debug")) |
31 | | - { |
32 | | - $params["Debug"] = $PSBoundParameters["Debug"] |
33 | | - } |
34 | | - if ($null -ne $PSBoundParameters["PipelineVariable"]) |
35 | | - { |
36 | | - $params["PipelineVariable"] = $PSBoundParameters["PipelineVariable"] |
37 | | - } |
38 | | - if ($null -ne $PSBoundParameters["InformationVariable"]) |
39 | | - { |
40 | | - $params["InformationVariable"] = $PSBoundParameters["InformationVariable"] |
41 | | - } |
42 | | - if ($null -ne $PSBoundParameters["Classification"]) |
43 | | - { |
44 | | - $params["Classification"] = $PSBoundParameters["Classification"] |
45 | | - } |
46 | | - if ($null -ne $PSBoundParameters["OutBuffer"]) |
47 | | - { |
48 | | - $params["OutBuffer"] = $PSBoundParameters["OutBuffer"] |
49 | | - } |
50 | | - if ($null -ne $PSBoundParameters["WarningVariable"]) |
51 | | - { |
52 | | - $params["WarningVariable"] = $PSBoundParameters["WarningVariable"] |
53 | | - } |
54 | | - if($PSBoundParameters.ContainsKey("Verbose")) |
55 | | - { |
56 | | - $params["Verbose"] = $PSBoundParameters["Verbose"] |
57 | | - } |
58 | | - if ($null -ne $PSBoundParameters["PermissionId"]) |
59 | | - { |
60 | | - $params["PermissionId"] = $PSBoundParameters["PermissionId"] |
61 | | - } |
62 | | - if ($null -ne $PSBoundParameters["PermissionName"]) |
63 | | - { |
64 | | - $params["PermissionName"] = $PSBoundParameters["PermissionName"] |
65 | | - } |
66 | | - if ($null -ne $PSBoundParameters["ErrorVariable"]) |
67 | | - { |
68 | | - $params["ErrorVariable"] = $PSBoundParameters["ErrorVariable"] |
69 | | - } |
70 | | - if ($null -ne $PSBoundParameters["ErrorAction"]) |
71 | | - { |
72 | | - $params["ErrorAction"] = $PSBoundParameters["ErrorAction"] |
73 | | - } |
74 | | - if ($null -ne $PSBoundParameters["InformationAction"]) |
75 | | - { |
76 | | - $params["InformationAction"] = $PSBoundParameters["InformationAction"] |
77 | | - } |
78 | | - if ($null -ne $PSBoundParameters["WarningAction"]) |
79 | | - { |
80 | | - $params["WarningAction"] = $PSBoundParameters["WarningAction"] |
81 | | - } |
82 | | - if ($null -ne $PSBoundParameters["ProgressAction"]) |
83 | | - { |
84 | | - $params["ProgressAction"] = $PSBoundParameters["ProgressAction"] |
85 | | - } |
86 | | - if ($null -ne $PSBoundParameters["OutVariable"]) |
87 | | - { |
88 | | - $params["OutVariable"] = $PSBoundParameters["OutVariable"] |
89 | | - } |
| 39 | + if ($null -ne $PSBoundParameters["ServicePrincipalId"]) { |
| 40 | + $params["ServicePrincipalId"] = $PSBoundParameters["ServicePrincipalId"] |
| 41 | + } |
| 42 | + if ($PSBoundParameters.ContainsKey("Debug")) { |
| 43 | + $params["Debug"] = $PSBoundParameters["Debug"] |
| 44 | + } |
| 45 | + if ($null -ne $PSBoundParameters["PipelineVariable"]) { |
| 46 | + $params["PipelineVariable"] = $PSBoundParameters["PipelineVariable"] |
| 47 | + } |
| 48 | + if ($null -ne $PSBoundParameters["InformationVariable"]) { |
| 49 | + $params["InformationVariable"] = $PSBoundParameters["InformationVariable"] |
| 50 | + } |
| 51 | + if ($null -ne $PSBoundParameters["Classification"]) { |
| 52 | + $params["Classification"] = $PSBoundParameters["Classification"] |
| 53 | + } |
| 54 | + if ($null -ne $PSBoundParameters["OutBuffer"]) { |
| 55 | + $params["OutBuffer"] = $PSBoundParameters["OutBuffer"] |
| 56 | + } |
| 57 | + if ($null -ne $PSBoundParameters["WarningVariable"]) { |
| 58 | + $params["WarningVariable"] = $PSBoundParameters["WarningVariable"] |
| 59 | + } |
| 60 | + if ($PSBoundParameters.ContainsKey("Verbose")) { |
| 61 | + $params["Verbose"] = $PSBoundParameters["Verbose"] |
| 62 | + } |
| 63 | + if ($null -ne $PSBoundParameters["PermissionId"]) { |
| 64 | + $params["PermissionId"] = $PSBoundParameters["PermissionId"] |
| 65 | + } |
| 66 | + if ($null -ne $PSBoundParameters["PermissionName"]) { |
| 67 | + $params["PermissionName"] = $PSBoundParameters["PermissionName"] |
| 68 | + } |
| 69 | + if ($null -ne $PSBoundParameters["ErrorVariable"]) { |
| 70 | + $params["ErrorVariable"] = $PSBoundParameters["ErrorVariable"] |
| 71 | + } |
| 72 | + if ($null -ne $PSBoundParameters["ErrorAction"]) { |
| 73 | + $params["ErrorAction"] = $PSBoundParameters["ErrorAction"] |
| 74 | + } |
| 75 | + if ($null -ne $PSBoundParameters["InformationAction"]) { |
| 76 | + $params["InformationAction"] = $PSBoundParameters["InformationAction"] |
| 77 | + } |
| 78 | + if ($null -ne $PSBoundParameters["WarningAction"]) { |
| 79 | + $params["WarningAction"] = $PSBoundParameters["WarningAction"] |
| 80 | + } |
| 81 | + if ($null -ne $PSBoundParameters["ProgressAction"]) { |
| 82 | + $params["ProgressAction"] = $PSBoundParameters["ProgressAction"] |
| 83 | + } |
| 84 | + if ($null -ne $PSBoundParameters["OutVariable"]) { |
| 85 | + $params["OutVariable"] = $PSBoundParameters["OutVariable"] |
| 86 | + } |
90 | 87 |
|
91 | | - Write-Debug("============================ TRANSFORMATIONS ============================") |
92 | | - $params.Keys | ForEach-Object {"$_ : $($params[$_])" } | Write-Debug |
93 | | - Write-Debug("=========================================================================`n") |
| 88 | + Write-Debug("============================ TRANSFORMATIONS ============================") |
| 89 | + $params.Keys | ForEach-Object { "$_ : $($params[$_])" } | Write-Debug |
| 90 | + Write-Debug("=========================================================================`n") |
94 | 91 |
|
95 | | - $response = New-MgServicePrincipalDelegatedPermissionClassification @params -Headers $customHeaders |
96 | | - $response | ForEach-Object { |
97 | | - if($null -ne $_) { |
98 | | - Add-Member -InputObject $_ -MemberType AliasProperty -Name ObjectId -Value Id |
| 92 | + $response = New-MgServicePrincipalDelegatedPermissionClassification @params -Headers $customHeaders |
| 93 | + $response | ForEach-Object { |
| 94 | + if ($null -ne $_) { |
| 95 | + Add-Member -InputObject $_ -MemberType AliasProperty -Name ObjectId -Value Id |
99 | 96 |
|
| 97 | + } |
100 | 98 | } |
101 | | - } |
102 | | - $response |
| 99 | + $response |
103 | 100 | } |
104 | 101 | } |
105 | 102 |
|
0 commit comments