2024-07-14 20:00:05 +02:00
|
|
|
[CmdletBinding()]
|
|
|
|
param (
|
|
|
|
|
|
|
|
[string]
|
|
|
|
$Identity,
|
|
|
|
[string]
|
|
|
|
$Server,
|
|
|
|
[string]
|
2024-07-15 15:42:37 +02:00
|
|
|
$ProjectName
|
2024-07-14 20:00:05 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
$User = $null
|
|
|
|
$Group = $null
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
if($null -eq $User){
|
|
|
|
throw "Didn't find the user, aborting"
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if($PSBoundParameters.ContainsKey("Server")){
|
2024-07-15 22:45:12 +02:00
|
|
|
$Group = . .\GetProjects.ps1 -Server $Server
|
2024-07-14 20:00:05 +02:00
|
|
|
} else {
|
2024-07-15 22:45:12 +02:00
|
|
|
$Group = . .\GetProjects.ps1
|
2024-07-14 20:00:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if($null -eq $Group){
|
|
|
|
throw "Can't find Project, aborting"
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
$targeGroup =$null
|
|
|
|
|
|
|
|
if($PSBoundParameters.ContainsKey("Server")){
|
|
|
|
$targeGroup = . .\GetRoles.ps1 -Server $Server -ProjectName $ProjectName
|
|
|
|
} else {
|
|
|
|
$targeGroup = . .\GetRoles.ps1 -ProjectName $ProjectName
|
|
|
|
}
|
|
|
|
|
|
|
|
if($null -eq $Group){
|
|
|
|
throw "Filter for Type was empty, aborting"
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if($PSBoundParameters.ContainsKey("Server")){
|
2024-07-14 20:05:25 +02:00
|
|
|
$targeGroup | ForEach-Object {Remove-ADGroupMember -Identity $_ -Members $Identity -Server $Server}
|
2024-07-14 20:00:05 +02:00
|
|
|
} else {
|
2024-07-14 20:05:25 +02:00
|
|
|
$targeGroup | ForEach-Object {Remove-ADGroupMember -Identity $_ -Members $Identity}
|
2024-07-14 20:00:05 +02:00
|
|
|
}
|