2024-07-14 19:32:03 +02:00
|
|
|
[CmdletBinding()]
|
|
|
|
param (
|
|
|
|
|
|
|
|
[string]
|
|
|
|
$Identity,
|
|
|
|
[string]
|
|
|
|
$Server,
|
|
|
|
[string]
|
2024-07-14 19:39:45 +02:00
|
|
|
$ProjectName,
|
|
|
|
[string]
|
|
|
|
$Type = "RO"
|
2024-07-14 19:32:03 +02:00
|
|
|
)
|
|
|
|
|
2024-07-14 19:50:50 +02:00
|
|
|
[ADUser]$User = $null
|
|
|
|
[ADGroup]$Group = $null
|
2024-07-14 19:32:03 +02:00
|
|
|
|
|
|
|
|
|
|
|
if(!$PSBoundParameters.ContainsKey("ProjectName")){
|
|
|
|
throw "ProjectName Parameter not specified, aborting"
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!$PSBoundParameters.ContainsKey("Identity")){
|
|
|
|
throw "Identity Parameter not specified, aborting"
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if($PSBoundParameters.ContainsKey("Server")){
|
|
|
|
$User = Get-ADUser -Server $Server -Identity $Identity
|
|
|
|
} else {
|
|
|
|
$User = Get-ADUser -Identity $Identity
|
|
|
|
}
|
|
|
|
|
2024-07-14 19:39:45 +02:00
|
|
|
if($null -eq $User){
|
2024-07-14 19:32:03 +02:00
|
|
|
throw "Didn't find the user, aborting"
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if($PSBoundParameters.ContainsKey("Server")){
|
|
|
|
$Group = . .\GetProjects.ps1 -Server $Server
|
|
|
|
} else {
|
|
|
|
$Group = . .\GetProjects.ps1
|
|
|
|
}
|
|
|
|
|
2024-07-14 19:39:45 +02:00
|
|
|
if($null -eq $Group){
|
|
|
|
throw "Can't find Project, aborting"
|
2024-07-14 19:32:03 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
$targeGroup =$null
|
|
|
|
|
|
|
|
if($PSBoundParameters.ContainsKey("Server")){
|
2024-07-14 19:50:50 +02:00
|
|
|
$targeGroup = . .\GetRoles.ps1 -Server $Server -ProjectName $ProjectName | Where-Object Name -Match $Type
|
2024-07-14 19:39:45 +02:00
|
|
|
} else {
|
2024-07-14 19:50:50 +02:00
|
|
|
$targeGroup = . .\GetRoles.ps1 -ProjectName $ProjectName | Where-Object Name -Match $Type
|
2024-07-14 19:39:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if($null -eq $Group){
|
|
|
|
throw "Filter for Type was empty, aborting"
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if($PSBoundParameters.ContainsKey("Server")){
|
|
|
|
Add-ADGroupMember -Identity $targeGroup -Members $User -Server $Server
|
2024-07-14 19:32:03 +02:00
|
|
|
} else {
|
2024-07-14 19:39:45 +02:00
|
|
|
Add-ADGroupMember -Identity $targeGroup -Members $User
|
2024-07-14 19:32:03 +02:00
|
|
|
}
|