From 81898676ed587c9693722128afd3003959cafea4 Mon Sep 17 00:00:00 2001 From: Karl-Wilfried Zimmer Date: Sun, 14 Jul 2024 20:00:05 +0200 Subject: [PATCH] renamed function --- RemoveUser.ps1 | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 RemoveUser.ps1 diff --git a/RemoveUser.ps1 b/RemoveUser.ps1 new file mode 100644 index 0000000..1a71be5 --- /dev/null +++ b/RemoveUser.ps1 @@ -0,0 +1,67 @@ +[CmdletBinding()] +param ( + + [string] + $Identity, + [string] + $Server, + [string] + $ProjectName, + [string] + $Type = "RO" +) + +$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")){ + $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 $Identity -Server $Server} +} else { + $targeGroup | ForEach-Object {Add-ADGroupMember -Identity $_ -Members $Identity} +} \ No newline at end of file