From 32e5c19230a7f636329b7d9656b0ae77344b778b Mon Sep 17 00:00:00 2001 From: Karl-Wilfried Zimmer Date: Sun, 14 Jul 2024 19:39:45 +0200 Subject: [PATCH] snap --- AddUser.ps1 | 25 +++++++++++++++++++------ GetRoles.ps1 | 4 +++- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/AddUser.ps1 b/AddUser.ps1 index 8ab4786..cbf759b 100644 --- a/AddUser.ps1 +++ b/AddUser.ps1 @@ -6,7 +6,9 @@ param ( [string] $Server, [string] - $ProjectName + $ProjectName, + [string] + $Type = "RO" ) $User = $null @@ -29,7 +31,7 @@ if($PSBoundParameters.ContainsKey("Server")){ $User = Get-ADUser -Identity $Identity } -if($User -eq $null){ +if($null -eq $User){ throw "Didn't find the user, aborting" return } @@ -40,15 +42,26 @@ if($PSBoundParameters.ContainsKey("Server")){ $Group = . .\GetProjects.ps1 } -if($Group -eq $null){ - throw "Can't find Project" +if($null -eq $Group){ + throw "Can't find Project, aborting" return } $targeGroup =$null if($PSBoundParameters.ContainsKey("Server")){ - Add-ADGroupMember -Identity -Members $User -Server $Server + $targeGroup = . .\GetRoles.ps1 -Server $Server -ProjectName $ProjectName } else { - Add-ADGroupMember -Identity -Members $User + $targeGroup = . .\GetRoles.ps1 -ProjectName $ProjectName +} + +if($null -eq $Group){ + throw "Filter for Type was empty, aborting" + return +} + +if($PSBoundParameters.ContainsKey("Server")){ + Add-ADGroupMember -Identity $targeGroup -Members $User -Server $Server +} else { + Add-ADGroupMember -Identity $targeGroup -Members $User } \ No newline at end of file diff --git a/GetRoles.ps1 b/GetRoles.ps1 index 239158a..6c8bb2f 100644 --- a/GetRoles.ps1 +++ b/GetRoles.ps1 @@ -1,7 +1,9 @@ [CmdletBinding()] param ( [string] - $Server + $Server, + [string] + $ProjectName ) $Projects=$null