2024-07-14 14:01:22 +02:00
|
|
|
[CmdletBinding()]
|
|
|
|
param (
|
|
|
|
[string]
|
|
|
|
$ProjectName,
|
|
|
|
[string]
|
|
|
|
$Server
|
|
|
|
)
|
|
|
|
|
|
|
|
. .\Variables.ps1
|
|
|
|
|
2024-07-14 17:15:12 +02:00
|
|
|
$ret=$null
|
|
|
|
$acls=$null
|
|
|
|
$rs=$null
|
|
|
|
|
2024-07-14 18:21:40 +02:00
|
|
|
$projPath=$BaseDirectory+$ProjectName
|
|
|
|
Write-Host $projPath
|
|
|
|
$testFolder = Test-Path -Path $projPath -PathType Container
|
|
|
|
|
|
|
|
if($testFolder){
|
|
|
|
throw "Directory already exists. Not creating Folder or Share"
|
|
|
|
}
|
|
|
|
|
2024-07-14 14:47:01 +02:00
|
|
|
if($PSBoundParameters.ContainsKey("ProjectName")){
|
2024-07-14 14:45:53 +02:00
|
|
|
if($PSBoundParameters.ContainsKey("Server")){
|
2024-07-14 16:27:01 +02:00
|
|
|
$ret = New-ADGroup -Path $Projects -Server $Server -Name $ProjectName -GroupCategory Security -GroupScope Global -PassThru
|
2024-07-14 16:45:30 +02:00
|
|
|
#$ret = Get-ADGroup $ProjectName -SearchBase $Projects -Server $Server
|
|
|
|
$acls = . .\AddProjectACL.ps1 -ProjectName $ProjectName -Server $Server
|
|
|
|
$rs = . .\AddProjectRoles.ps1 -ProjectName $ProjectName -Server $Server
|
2024-07-14 14:45:53 +02:00
|
|
|
#$ret | Add-ADGroupMember -Members $acl,$r
|
2024-07-14 16:45:30 +02:00
|
|
|
$acls | ForEach-Object {add-ADGroupMember -Identity $ret -Members $_ -Server $Server}
|
|
|
|
$rs | ForEach-Object {Add-ADGroupMember -Identity $ret -Members $_ -Server $Server}
|
2024-07-14 14:45:53 +02:00
|
|
|
} else {
|
2024-07-14 16:27:01 +02:00
|
|
|
$ret = New-ADGroup -Path $Projects -Name $ProjectName -GroupCategory Security -GroupScope Global -PassThru
|
2024-07-14 16:45:30 +02:00
|
|
|
#$ret = Get-ADGroup $ProjectName -SearchBase $Projects
|
|
|
|
$acls = . .\AddProjectACL.ps1 -ProjectName $ProjectName
|
|
|
|
$rs = . .\AddProjectRoles.ps1 -ProjectName $ProjectName
|
2024-07-14 14:45:53 +02:00
|
|
|
#$ret | Add-ADGroupMember -Members $acl,$r
|
2024-07-14 16:45:30 +02:00
|
|
|
$acls | ForEach-Object {Add-ADGroupMember -Identity $ret -Members $_}
|
|
|
|
$rs | ForEach-Object {Add-ADGroupMember -Identity $ret -Members $_}
|
2024-07-14 14:45:53 +02:00
|
|
|
}
|
|
|
|
|
2024-07-14 17:15:12 +02:00
|
|
|
if($PSBoundParameters.ContainsKey("Server")){
|
2024-07-14 17:47:06 +02:00
|
|
|
$target = $acls | Where-Object Name -Match ".*-RW"
|
|
|
|
$member = $rs | Where-Object Name -Match ".*-RW"
|
2024-07-14 17:15:12 +02:00
|
|
|
Add-ADGroupMember -Identity $target -Members $member -Server $Server
|
2024-07-14 17:47:06 +02:00
|
|
|
$target = $acls | Where-Object Name -Match ".*-RO"
|
|
|
|
$member = $rs | Where-Object Name -Match ".*-RO"
|
2024-07-14 17:15:12 +02:00
|
|
|
Add-ADGroupMember -Identity $target -Members $member -Server $Server
|
|
|
|
} else {
|
2024-07-14 17:47:06 +02:00
|
|
|
$target = $acls | Where-Object Name -Match ".*-RW"
|
|
|
|
$member = $rs | Where-Object Name -Match ".*-RW"
|
2024-07-14 17:15:12 +02:00
|
|
|
Add-ADGroupMember -Identity $target -Members $member
|
2024-07-14 17:47:06 +02:00
|
|
|
$target = $acls | Where-Object Name -Match ".*-RO"
|
|
|
|
$member = $rs | Where-Object Name -Match ".*-RO"
|
2024-07-14 17:15:12 +02:00
|
|
|
Add-ADGroupMember -Identity $target -Members $member
|
|
|
|
}
|
2024-07-14 18:21:40 +02:00
|
|
|
|
|
|
|
|
|
|
|
$folder = New-Item -Path $projPath -ItemType Directory
|
2024-07-14 17:15:12 +02:00
|
|
|
|
2024-07-14 19:05:23 +02:00
|
|
|
$ReadTarget = $acls | Where-Object Name -Match ".*-RO"
|
|
|
|
$WriteTarget = $acls | Where-Object Name -Match ".*-RW"
|
2024-07-14 19:03:07 +02:00
|
|
|
Write-Host $ReadTarget.Name
|
|
|
|
Write-Host $WriteTarget.Name
|
2024-07-14 17:15:12 +02:00
|
|
|
|
2024-07-14 18:21:40 +02:00
|
|
|
$Parameters = @{
|
|
|
|
Name=$ProjectName
|
|
|
|
Path=$projPath
|
|
|
|
}
|
2024-07-14 17:47:06 +02:00
|
|
|
|
2024-07-14 19:03:07 +02:00
|
|
|
|
|
|
|
|
2024-07-14 18:21:40 +02:00
|
|
|
$share = New-SmbShare @Parameters
|
|
|
|
$share|Set-SmbShare -FolderEnumerationMode AccessBased
|
2024-07-14 19:03:07 +02:00
|
|
|
$share|Grant-SmbShareAccess -AccountName $ReadTarget.Name -AccessRight Read
|
|
|
|
$share|Grant-SmbShareAccess -AccountName $WriteTarget.Name -AccessRight Change
|
2024-07-14 17:15:12 +02:00
|
|
|
|
2024-07-14 14:45:53 +02:00
|
|
|
return $ret
|
2024-07-14 14:26:26 +02:00
|
|
|
}
|
|
|
|
|
2024-07-14 14:45:53 +02:00
|
|
|
throw "ProjectName parameter needs to be set"
|
2024-07-14 14:26:26 +02:00
|
|
|
|