-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConvertDelegatedPermissionsToNewUsers.ps1
60 lines (54 loc) · 1.67 KB
/
ConvertDelegatedPermissionsToNewUsers.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[string]
$PermissionsFile,
[Parameter(Mandatory = $true)]
[string]
$MappingUsersFile,
[Parameter(Mandatory = $true)]
[string]
$MappingSharedMailboxFile,
[Parameter(Mandatory = $true)]
[string]
$OutputFile
)
BEGIN{
$ErrorActionPreference = "Stop"
$Mapping = @()
$Mapping += Import-csv $MappingUsersFile
$Mapping += Import-Csv $MappingSharedMailboxFile
$MappingHash = $Mapping | Group-Object OldUPN -AsHashTable
$CSV = Import-Csv $PermissionsFile
}
PROCESS{
$results = @()
foreach ($Line in $CSV){
$OldEmail = $Line.Email
$OldUserGrantedPermission = $Line.UserGrantedPermission
$Permission = $line.Permission
$NewEmail = $MappingHash[$OldEmail].NewUPN
if(-not $NewEmail){
Write-Host "Email '$OldEmail' not in mapping..." -ForegroundColor Cyan
continue
}
$NewUserGrantedPermission = $MappingHash[$OldUserGrantedPermission].NewUPN
if(-not $NewUserGrantedPermission){
Write-Host "User Granted Permission '$OldUserGrantedPermission' not in mapping..." -ForegroundColor Cyan
continue
}
$results += [PSCustomObject]@{
Email = $OldEmail
NewEmail = $NewEmail
UserGrantedPermission = $OldUserGrantedPermission
NewUserGrantedPermission = $NewUserGrantedPermission
Permission = $Permission
}
}
}
END{
if($results){
$results | Export-Csv -NoTypeInformation -LiteralPath $OutputFile
Write-Host "Results saved to: '$OutputFile'" -ForegroundColor Green
}
}