From 13cf8245075fdb3fc99c31184b6a8b376712df5a Mon Sep 17 00:00:00 2001 From: Karl-Wilfried Zimmer Date: Sun, 14 Jul 2024 17:47:06 +0200 Subject: [PATCH] snap: foldercreation working, problems with creating share --- NewProject.ps1 | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/NewProject.ps1 b/NewProject.ps1 index 42b5fd6..e322f3b 100644 --- a/NewProject.ps1 +++ b/NewProject.ps1 @@ -32,22 +32,43 @@ if($PSBoundParameters.ContainsKey("ProjectName")){ } if($PSBoundParameters.ContainsKey("Server")){ - $target = $acls | Where-Object Name -Match ".*RW" - $member = $rs | Where-Object Name -Match ".*RW" + $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" + $target = $acls | Where-Object Name -Match ".*-RO" + $member = $rs | Where-Object Name -Match ".*-RO" Add-ADGroupMember -Identity $target -Members $member -Server $Server } else { - $target = $acls | Where-Object Name -Match ".*RW" - $member = $rs | Where-Object Name -Match ".*RW" + $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" + $target = $acls | Where-Object Name -Match ".*-RO" + $member = $rs | Where-Object Name -Match ".*-RO" Add-ADGroupMember -Identity $target -Members $member } + $testFolder = Test-Path "$BaseDirectory+$ProjectName" -PathType Container + if($testFolder){ + throw "Directory already exists. Not creating Folder or Share" + } else { + $projPath=$BaseDirectory+$ProjectName + Write-Host $projPath + $folder = New-Item -Path $projPath -ItemType Directory + + $ReadTarget = $acls | Where-Object Name -Match ".*RW" + $WriteTarget = $acls | Where-Object Name -Match ".*RO" + + $Parameters = @{ + Name=$ProjectName + Path=$projPath + ChangeAccess=$WriteTarget.SID + ReadAccess=$ReadTarget.SID + } + + $share = New-SmbShare @Parameters + $share|Set-SmbShare -FolderEnumerationMode AccessBased + } return $ret }