-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #76 from kayasax/copyassignment
V1.7.4
- Loading branch information
Showing
3 changed files
with
119 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
EasyPIM/functions/Copy-PIMAzureResourceEligibleAssignment.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<# | ||
.Synopsis | ||
Copy eligible assignement from one user to another | ||
.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 from | ||
userprincipalname or objectID of the source object | ||
.Parameter to | ||
userprincipalname or objectID of the destination object | ||
.Example | ||
PS> Copy-PIMAzureResourceEligibleAssignment -tenantID $tid -subscriptionID -subscription $subscription -from [email protected] -to [email protected] | ||
Copy eligible assignement from user1 to user2 | ||
.Link | ||
.Notes | ||
Author: Loïc MICHEL | ||
Homepage: https://github.com/kayasax/EasyPIM | ||
#> | ||
|
||
function Copy-PIMAzureResourceEligibleAssignment { | ||
[CmdletBinding()] | ||
param ( | ||
[Parameter(Position = 0, Mandatory = $true)] | ||
[String] | ||
$tenantID, | ||
[Parameter(Position = 1)] | ||
[String] | ||
$subscriptionID, | ||
[Parameter()] | ||
[String] | ||
$scope, | ||
[Parameter(Mandatory = $true)] | ||
[String] | ||
$from, | ||
[Parameter(Mandatory = $true)] | ||
[String] | ||
$to | ||
) | ||
|
||
try { | ||
|
||
$script:tenantID = $tenantID | ||
|
||
if (!($PSBoundParameters.Keys.Contains('scope'))) { | ||
$scope = "/subscriptions/$subscriptionID" | ||
} | ||
|
||
#convert UPN to objectID | ||
if ($from -match ".+@.*\..+") { | ||
#if this is a upn we will use graph to get the objectID | ||
try { | ||
$resu = invoke-graph -endpoint "users/$from" -Method GET -version "beta" | ||
$from = $resu.id | ||
} | ||
catch { | ||
Write-Warning "User $from not found in the tenant" | ||
return | ||
} | ||
|
||
} | ||
|
||
if ($to -match ".+@.*\..+") { | ||
#if this is a upn we will use graph to get the objectID | ||
try { | ||
$resu = invoke-graph -endpoint "users/$to" -Method GET -version "beta" | ||
$to = $resu.id | ||
} | ||
catch { | ||
Write-Warning "User $to not found in the tenant" | ||
return | ||
} | ||
|
||
} | ||
|
||
$assignments=get-PIMAzureResourceEligibleAssignment -tenantID $tenantID -scope $scope -assignee $from | ||
$assignments | ForEach-Object { | ||
Write-Verbose "Copying assignment from $from to $to at scope $($_.scopeId) with role $($_.rolename)" | ||
New-PIMAzureResourceEligibleAssignment -tenantID $tenantID -subscriptionID $subscriptionID -scope $_.scopeId -rolename $_.rolename -principalID $to | ||
} | ||
|
||
} | ||
catch { | ||
MyCatch $_ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters