Skip to content

Commit

Permalink
Merge pull request #27 from kayasax/Groups
Browse files Browse the repository at this point in the history
Groups
  • Loading branch information
kayasax authored Mar 8, 2024
2 parents 177eb10 + 2e0428e commit 0e32f9e
Show file tree
Hide file tree
Showing 12 changed files with 1,278 additions and 5 deletions.
12 changes: 10 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.4.0'
ModuleVersion = '1.5.0'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down Expand Up @@ -85,7 +85,15 @@ FunctionsToExport = @(
"New-PIMEntraRoleActiveAssignment",
"New-PIMEntraRoleEligibleAssignment",
'Remove-PIMEntraRoleActiveAssignment',
'Remove-PIMEntraRoleEligibleAssignment'
'Remove-PIMEntraRoleEligibleAssignment',
"Get-PIMGroupPolicy",
"Set-PIMGroupPolicy",
"Get-PIMGroupActiveAssignment",
"Get-PIMGroupEligibleAssignment",
'New-PIMGroupActiveAssignment',
'New-PIMGroupEligibleAssignment',
'Remove-PIMGroupActiveAssignment',
'Remove-PIMGroupEligibleAssignment'
)

# 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
91 changes: 91 additions & 0 deletions EasyPIM/functions/Get-PIMGroupActiveAssignment.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<#
.Synopsis
List of PIM Entra Role active assignement
.Description
Active assignment does not require to activate their role. https://learn.microsoft.com/en-us/graph/api/rbacapplication-list-roleeligibilityscheduleinstances?view=graph-rest-1.0&tabs=http
.Parameter tenantID
EntraID tenant ID
.Parameter summary
When enabled will return the most useful information only
.PARAMETER rolename
Filter by rolename
.PARAMETER principalid
Filter by principalid
.PARAMETER principalName
Filter by principalName
.Example
PS> Get-PIMEntraRoleActiveAssignment -tenantID $tid
List active assignement
.Link
.Notes
Author: Loïc MICHEL
Homepage: https://github.com/kayasax/EasyPIM
#>

function Get-PIMGroupActiveAssignment {
[CmdletBinding()]
param (
[Parameter(Position = 0, Mandatory = $true)]
[String]
$tenantID,
# select the most usefull info only
[switch]$summary,
[string]$groupID,
[string]$rolename,
[string]$principalName
)

try {
$script:tenantID = $tenantID

$endpoint = "identityGovernance/privilegedAccess/group/assignmentSchedules?`$filter=groupId eq '$groupID'&`$expand=principal
"
$response = invoke-graph -Endpoint $endpoint
$resu = @()
$response.value | ForEach-Object {

$r = @{
#"rolename" = $_.roledefinition.displayName
#"roleid" = $_.roledefinition.id
"principalname" = $_.principal.displayName
"principalid" = $_.principal.id
"principalEmail" = $_.principal.mail
"startDateTime" = $_.scheduleInfo.startDateTime
"endDateTime" = $_.scheduleInfo.expiration.endDateTime
#"directoryScopeId" = $_.directoryScopeId
"memberType" = $_.accessId
"assignmentType" = $_.memberType
#"activatedUsing"=$_.activatedUsing
"principaltype" = $_.principal."@odata.type"
"id" = $_.id
}
$resu += New-Object PSObject -Property $r


}

if ($PSBoundParameters.Keys.Contains('summary')) {
$resu = $resu | Select-Object rolename, roleid, principalid, principalName, principalEmail, PrincipalType, startDateTime, endDateTime, directoryScopeId
}

if ($PSBoundParameters.Keys.Contains('principalid')) {
$resu = $resu | Where-Object { $_.principalid -eq $principalid }
}

if ($PSBoundParameters.Keys.Contains('rolename')) {
$resu = $resu | Where-Object { $_.rolename -eq $rolename }
}
if($PSBoundParameters.Keys.Contains('principalName')){
$resu = $resu | Where-Object { $_.principalName -match $principalName }
}

return $resu
}
catch {
MyCatch $_
}
}
91 changes: 91 additions & 0 deletions EasyPIM/functions/Get-PIMGroupEligibleAssignment.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<#
.Synopsis
List of PIM Entra Role active assignement
.Description
Active assignment does not require to activate their role. https://learn.microsoft.com/en-us/graph/api/rbacapplication-list-roleeligibilityscheduleinstances?view=graph-rest-1.0&tabs=http
.Parameter tenantID
EntraID tenant ID
.Parameter summary
When enabled will return the most useful information only
.PARAMETER rolename
Filter by rolename
.PARAMETER principalid
Filter by principalid
.PARAMETER principalName
Filter by principalName
.Example
PS> Get-PIMEntraRoleActiveAssignment -tenantID $tid
List active assignement
.Link
.Notes
Author: Loïc MICHEL
Homepage: https://github.com/kayasax/EasyPIM
#>

function Get-PIMGroupEligibleAssignment {
[CmdletBinding()]
param (
[Parameter(Position = 0, Mandatory = $true)]
[String]
$tenantID,
# select the most usefull info only
[switch]$summary,
[string]$groupID,
[string]$rolename,
[string]$principalName
)

try {
$script:tenantID = $tenantID

$endpoint = "identityGovernance/privilegedAccess/group/eligibilitySchedules?`$filter=groupId eq '$groupID'&`$expand=principal
"
$response = invoke-graph -Endpoint $endpoint
$resu = @()
$response.value | ForEach-Object {

$r = @{
#"rolename" = $_.roledefinition.displayName
##"roleid" = $_.roledefinition.id
"principalname" = $_.principal.displayName
"principalid" = $_.principal.id
"principalEmail" = $_.principal.mail
"startDateTime" = $_.scheduleInfo.startDateTime
"endDateTime" = $_.scheduleInfo.expiration.endDateTime
#"directoryScopeId" = $_.directoryScopeId
"memberType" = $_.accessId
"assignmentType" = $_.memberType
#"activatedUsing"=$_.activatedUsing
"principaltype" = $_.principal."@odata.type"
"id" = $_.id
}
$resu += New-Object PSObject -Property $r


}

if ($PSBoundParameters.Keys.Contains('summary')) {
$resu = $resu | Select-Object rolename, roleid, principalid, principalName, principalEmail, PrincipalType, startDateTime, endDateTime, directoryScopeId
}

if ($PSBoundParameters.Keys.Contains('principalid')) {
$resu = $resu | Where-Object { $_.principalid -eq $principalid }
}

if ($PSBoundParameters.Keys.Contains('rolename')) {
$resu = $resu | Where-Object { $_.rolename -eq $rolename }
}
if($PSBoundParameters.Keys.Contains('principalName')){
$resu = $resu | Where-Object { $_.principalName -match $principalName }
}

return $resu
}
catch {
MyCatch $_
}
}
88 changes: 88 additions & 0 deletions EasyPIM/functions/Get-PIMGroupPolicy.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<#
.Synopsis
EASYPIM
Powershell module to manage PIM Azure Resource Role settings with simplicity in mind
Get-PIMGroupPolicy will return the policy rules (like require MFA on activation) of the selected rolename at the subscription level
Support querrying multi roles at once
.Description
Get-PIMGroupPolicy will use the Microsoft Graph APIs to retrieve the PIM settings of the role $rolename
.PARAMETER tenantID
Tenant ID
.PARAMETER GroupID
Id of the group to check
.PARAMETER GroupName
Search for the group by name
.Example
PS> Get-PIMGroupPolicy -tenantID $tenantID -rolename "Global Administrator","Global Reader"
show curent config for the roles global administrator and global reader
.Link
https://learn.microsoft.com/en-us/azure/governance/resource-graph/first-query-rest-api
https://learn.microsoft.com/en-us/graph/identity-governance-pim-rules-overview
Duration ref https://en.wikipedia.org/wiki/ISO_8601#Durations
.Notes
Homepage: https://github.com/kayasax/easyPIM
Author: MICHEL, Loic
Changelog:
Todo:
* allow other scopes
#>
function Get-PIMGroupPolicy {
[CmdletBinding()]
[OutputType([PSCustomObject])]
param (

[Parameter(Position = 0, Mandatory = $true)]
[System.String]
# Tenant ID
$tenantID,

[Parameter(Position = 1)]
[System.String[]]
# Array of role name
$groupID,

[Parameter(Position = 2)]
[System.String]
# Array of role name
$groupName,

[Parameter(Mandatory = $true)]
[System.String]
#owner or member
$type


)
try {
$script:tenantID = $tenantID

if ($PSBoundParameters.ContainsKey('groupname')) {
$endpoint="/groups?`$filter=startswith(displayName,'$($groupName)')"
$response=invoke-graph -Endpoint $endpoint
$groupID+=$response.value.id

}


$out = @()
$groupID | ForEach-Object {

#get curent config
$config = get-GroupConfig $_ $type
$out += $config
}
Write-Output $out -NoEnumerate
}
catch {
MyCatch $_
}

}
4 changes: 2 additions & 2 deletions EasyPIM/functions/New-PIMEntraRoleActiveAssignment.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ function New-PIMEntraRoleActiveAssignment {
}
},
"ticketInfo": {
"ticketNumber": "CONTOSO:Normal-67890",
"ticketSystem": "MS Project"
"ticketNumber": "EasyPIM",
"ticketSystem": "EasyPIM"
}
}
Expand Down
Loading

0 comments on commit 0e32f9e

Please sign in to comment.