ProjectManagementScripts/NewProject.ps1
2024-07-14 17:15:12 +02:00

57 lines
2.2 KiB
PowerShell

[CmdletBinding()]
param (
[string]
$ProjectName,
[string]
$Server
)
. .\Variables.ps1
$ret=$null
$acls=$null
$rs=$null
if($PSBoundParameters.ContainsKey("ProjectName")){
if($PSBoundParameters.ContainsKey("Server")){
$ret = New-ADGroup -Path $Projects -Server $Server -Name $ProjectName -GroupCategory Security -GroupScope Global -PassThru
#$ret = Get-ADGroup $ProjectName -SearchBase $Projects -Server $Server
$acls = . .\AddProjectACL.ps1 -ProjectName $ProjectName -Server $Server
$rs = . .\AddProjectRoles.ps1 -ProjectName $ProjectName -Server $Server
#$ret | Add-ADGroupMember -Members $acl,$r
$acls | ForEach-Object {add-ADGroupMember -Identity $ret -Members $_ -Server $Server}
$rs | ForEach-Object {Add-ADGroupMember -Identity $ret -Members $_ -Server $Server}
} else {
$ret = New-ADGroup -Path $Projects -Name $ProjectName -GroupCategory Security -GroupScope Global -PassThru
#$ret = Get-ADGroup $ProjectName -SearchBase $Projects
$acls = . .\AddProjectACL.ps1 -ProjectName $ProjectName
$rs = . .\AddProjectRoles.ps1 -ProjectName $ProjectName
#$ret | Add-ADGroupMember -Members $acl,$r
$acls | ForEach-Object {Add-ADGroupMember -Identity $ret -Members $_}
$rs | ForEach-Object {Add-ADGroupMember -Identity $ret -Members $_}
}
if($PSBoundParameters.ContainsKey("Server")){
$target = $acls | Where-Object Name -Match ".*RW"
$member = $rs | Where-Object Name -Match ".*RW"
Add-ADGroupMember -Identity $target -Members $member -Server $Server
$target = $acls | Where-Object Name -Match ".*RW"
$member = $rs | Where-Object Name -Match ".*RW"
Add-ADGroupMember -Identity $target -Members $member -Server $Server
} else {
$target = $acls | Where-Object Name -Match ".*RW"
$member = $rs | Where-Object Name -Match ".*RW"
Add-ADGroupMember -Identity $target -Members $member
$target = $acls | Where-Object Name -Match ".*RW"
$member = $rs | Where-Object Name -Match ".*RW"
Add-ADGroupMember -Identity $target -Members $member
}
return $ret
}
throw "ProjectName parameter needs to be set"