Skip to content

Commit

Permalink
Merge pull request #13 from kayasax/assignment
Browse files Browse the repository at this point in the history
EasyPIM V1.2.0
  • Loading branch information
kayasax authored Feb 5, 2024
2 parents 63ec482 + 1616b39 commit 4f3e6a0
Show file tree
Hide file tree
Showing 10 changed files with 832 additions and 4 deletions.
15 changes: 15 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "PowerShell: Launch Current File",
"type": "PowerShell",
"request": "launch",
"script": "${file}",
"args": []
}
]
}
15 changes: 13 additions & 2 deletions EasyPIM/EasyPIM.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
RootModule = 'EasyPIM.psm1'

# Version number of this module.
ModuleVersion = '1.1.0'
ModuleVersion = '1.2.0'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down Expand Up @@ -62,7 +62,18 @@ Description = 'Powershell module to manage PIM Azure Resource Role settings with

# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
FunctionsToExport = @(
"Import-PIMAzureResourcePolicy","Get-PIMAzureResourcePolicy","Set-PIMAzureResourcePolicy","Copy-PIMAzureResourcePolicy","Export-PIMAzureResourcePolicy","Backup-PIMAzureResourcePolicy"
"Import-PIMAzureResourcePolicy",
"Get-PIMAzureResourcePolicy",
"Set-PIMAzureResourcePolicy",
"Copy-PIMAzureResourcePolicy",
"Export-PIMAzureResourcePolicy",
"Backup-PIMAzureResourcePolicy",
"Get-PIMAzureResourceActiveAssignment",
"Get-PIMAzureResourceEligibleAssignment",
"New-PIMAzureResourceActiveAssignment",
"New-PIMAzureResourceEligibleAssignment",
"Remove-PIMAzureResourceEligibleAssignment",
"Remove-PIMAzureResourceActiveAssignment"
)

# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
Expand Down
103 changes: 103 additions & 0 deletions EasyPIM/functions/Get-PIMAzureResourceActiveAssignment.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<#
.Synopsis
List of active assignement defined at the provided scope or bellow
.Description
Active assignment does not require to activate their role. https://learn.microsoft.com/en-us/entra/id-governance/privileged-identity-management/pim-resource-roles-assign-roles
.Parameter tenantID
EntraID tenant ID
.Parameter subscriptionID
subscription ID
.Parameter scope
use scope parameter if you want to work at other scope than a subscription
.Parameter summary
When enabled will return the most useful information only
.Parameter atBellowScope
Will return only the assignment defined at lower scopes
.Example
PS> Get-PIMAzureResourceActiveAssignment -tenantID $tid -subscriptionID -subscription $subscription
List active assignement at the subscription scope.
.Link
https://learn.microsoft.com/en-us/entra/id-governance/privileged-identity-management/pim-resource-roles-assign-roles
.Notes
Author: Loïc MICHEL
Homepage: https://github.com/kayasax/EasyPIM
#>

function Get-PIMAzureResourceActiveAssignment {
[CmdletBinding()]
param (
[Parameter(Position = 0, Mandatory = $true)]
[String]
$tenantID,
[Parameter(Position = 1)]
[String]
$subscriptionID,
[Parameter()]
[String]
$scope,
[switch]
# select the most usefull info only
$summary,
[switch]
# return only assignment defined at a lower scope
$atBellowScope
)

if (!($PSBoundParameters.Keys.Contains('scope'))) {
$scope = "/subscriptions/$subscriptionID"
}
$restURI = "https://management.azure.com/$scope/providers/Microsoft.Authorization/roleAssignmentSchedules?api-version=2020-10-01"

$script:tenantID=$tenantID

$response = Invoke-ARM -restURI $restURI -method get
#$response|select -first 1

$return = @()
#$id=$response.value.id
#$response.value.properties |get-member

$response.value | ForEach-Object {
$id = $_.id
#echo "ID: $id"
$_.properties | ForEach-Object {
#$_
if ($null -eq $_.endDateTime ) { $end = "permanent" }else { $end = $_.endDateTime }
$properties = @{
"PrincipalName" = $_.expandedproperties.principal.displayName
"PrincipalEmail" = $_.expandedproperties.principal.email;
"PrincipalType" = $_.expandedproperties.principal.type;
"PrincipalId" = $_.expandedproperties.principal.id;
"RoleName" = $_.expandedproperties.roleDefinition.displayName;
"RoleType" = $_.expandedproperties.roleDefinition.type;
"RoleId" = $_.expandedproperties.roleDefinition.id;
"ScopeId" = $_.expandedproperties.scope.id;
"ScopeName" = $_.expandedproperties.scope.displayName;
"ScopeType" = $_.expandedproperties.scope.type;
"Status" = $_.Status;
"createdOn" = $_.createdOn
"startDateTime" = $_.startDateTime
"endDateTime" = $end
"updatedOn" = $_.updatedOn
"memberType" = $_.memberType
"id" = $id
}


$obj = New-Object pscustomobject -Property $properties
$return += $obj
}
}

if ($PSBoundParameters.Keys.Contains('summary')) {
$return = $return | Select-Object scopeid, rolename, roletype, principalid, principalName, principalEmail, PrincipalType, status, startDateTime, endDateTime
}
if ($PSBoundParameters.Keys.Contains('atBellowScope')) {
$return = $return | Where-Object { $($_.scopeid).Length -gt $scope.Length }
}
return $return
}
103 changes: 103 additions & 0 deletions EasyPIM/functions/Get-PIMAzureResourceEligibleAssignment.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<#
.Synopsis
List of eligible assignement defined at the provided scope or bellow
.Description
https://learn.microsoft.com/en-us/entra/id-governance/privileged-identity-management/pim-resource-roles-assign-roles
.Parameter tenantID
EntraID tenant ID
.Parameter subscriptionID
subscription ID
.Parameter scope
use scope parameter if you want to work at other scope than a subscription
.Parameter summary
When enabled will return the most useful information only
.Parameter atBellowScope
Will return only the assignment defined at lower scopes
.Example
PS> Get-PIMAzureResourceEligibleAssignment -tenantID $tid -subscriptionID -subscription $subscription
List active assignement at the subscription scope.
.Link
https://learn.microsoft.com/en-us/entra/id-governance/privileged-identity-management/pim-resource-roles-assign-roles
.Notes
Author: Loïc MICHEL
Homepage: https://github.com/kayasax/EasyPIM
#>

function Get-PIMAzureResourceEligibleAssignment {
[CmdletBinding()]
param (
[Parameter(Position = 0, Mandatory = $true)]
[String]
$tenantID,
[Parameter(Position = 1)]
[String]
$subscriptionID,
[Parameter()]
[String]
$scope,
[switch]
# select the most usefull info only
$summary,
[switch]
# return only assignment defined at a lower scope
$atBellowScope
)

if (!($PSBoundParameters.Keys.Contains('scope'))) {
$scope = "/subscriptions/$subscriptionID"
}
$restURI = "https://management.azure.com/$scope/providers/Microsoft.Authorization/roleEligibilitySchedules?api-version=2020-10-01"

$script:tenantID=$tenantID

$response = Invoke-ARM -restURI $restURI -method get
#$response|select -first 1

$return = @()
#$id=$response.value.id
#$response.value.properties |get-member

$response.value | ForEach-Object {
$id = $_.id
#echo "ID: $id"
$_.properties | ForEach-Object {
#$_
if ($null -eq $_.endDateTime ) { $end = "permanent" }else { $end = $_.endDateTime }
$properties = @{
"PrincipalName" = $_.expandedproperties.principal.displayName
"PrincipalEmail" = $_.expandedproperties.principal.email;
"PrincipalType" = $_.expandedproperties.principal.type;
"PrincipalId" = $_.expandedproperties.principal.id;
"RoleName" = $_.expandedproperties.roleDefinition.displayName;
"RoleType" = $_.expandedproperties.roleDefinition.type;
"RoleId" = $_.expandedproperties.roleDefinition.id;
"ScopeId" = $_.expandedproperties.scope.id;
"ScopeName" = $_.expandedproperties.scope.displayName;
"ScopeType" = $_.expandedproperties.scope.type;
"Status" = $_.Status;
"createdOn" = $_.createdOn
"startDateTime" = $_.startDateTime
"endDateTime" = $end
"updatedOn" = $_.updatedOn
"memberType" = $_.memberType
"id" = $id
}


$obj = New-Object pscustomobject -Property $properties
$return += $obj
}
}

if ($PSBoundParameters.Keys.Contains('summary')) {
$return = $return | Select-Object scopeid, rolename, roletype, principalid, principalName, principalEmail, PrincipalType, status, startDateTime, endDateTime
}
if ($PSBoundParameters.Keys.Contains('atBellowScope')) {
$return = $return | Where-Object { $($_.scopeid).Length -gt $scope.Length }
}
return $return
}
2 changes: 1 addition & 1 deletion EasyPIM/functions/Get-PIMAzureResourcePolicy.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Subscription ID
Name of the role to check
.Example
PS> Get-PIMAzureResourcePolicy -subscription $subscriptionID -rolename "contributor","webmaster"
PS> Get-PIMAzureResourcePolicy -tenantID $tenantID -subscriptionID $subscriptionID -rolename "contributor","webmaster"
show curent config for the roles contributor and webmaster at the subscriptionID scope :
Expand Down
Loading

0 comments on commit 4f3e6a0

Please sign in to comment.