ProjectManagementScripts/AddUser.ps1
2024-07-14 19:32:03 +02:00

54 lines
1.0 KiB
PowerShell

[CmdletBinding()]
param (
[string]
$Identity,
[string]
$Server,
[string]
$ProjectName
)
$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($User -eq $null){
throw "Didn't find the user, aborting"
return
}
if($PSBoundParameters.ContainsKey("Server")){
$Group = . .\GetProjects.ps1 -Server $Server
} else {
$Group = . .\GetProjects.ps1
}
if($Group -eq $null){
throw "Can't find Project"
return
}
$targeGroup =$null
if($PSBoundParameters.ContainsKey("Server")){
Add-ADGroupMember -Identity -Members $User -Server $Server
} else {
Add-ADGroupMember -Identity -Members $User
}