added remove user commandlet

This commit is contained in:
Karl-Wilfried Zimmer 2024-07-14 19:54:56 +02:00
parent b81203e562
commit 7727c89975

67
RemoveUser copy.ps1 Normal file
View File

@ -0,0 +1,67 @@
[CmdletBinding()]
param (
[string]
$Identity,
[string]
$Server,
[string]
$ProjectName,
[string]
$Type = "RO"
)
[ADUser]$User = $null
[ADGroup]$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")){
$Group = . .\GetProjects.ps1 -Server $Server
} else {
$Group = . .\GetProjects.ps1
}
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")){
$targeGroup | ForEach-Object {Add-ADGroupMember -Identity $_ -Members $User -Server $Server}
} else {
$targeGroup | ForEach-Object {Add-ADGroupMember -Identity $_ -Members $User}
}