ProjectManagementScripts/NewProject.ps1

83 lines
3.0 KiB
PowerShell
Raw Permalink Normal View History

[CmdletBinding()]
param (
[string]
$ProjectName,
[string]
$Server
)
. .\Variables.ps1
2024-07-14 17:15:12 +02:00
$ret=$null
$acls=$null
$rs=$null
$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")){
$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
$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 {
$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
$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 20:41:49 +02:00
$folder = New-Item -Path $projPath -ItemType Directory
2024-07-14 17:15:12 +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
$Parameters = @{
Name=$ProjectName
Path=$projPath
}
2024-07-14 19:03:07 +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:45:53 +02:00
throw "ProjectName parameter needs to be set"