From b243ac2a36b84f5ec3a1e90d40e73d22f72041af Mon Sep 17 00:00:00 2001 From: Karl-Wilfried Zimmer Date: Sun, 14 Jul 2024 18:21:40 +0200 Subject: [PATCH] snap: smb share creation possible without any specification of access rights --- NewProject.ps1 | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/NewProject.ps1 b/NewProject.ps1 index e322f3b..1000567 100644 --- a/NewProject.ps1 +++ b/NewProject.ps1 @@ -12,6 +12,14 @@ $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" +} + if($PSBoundParameters.ContainsKey("ProjectName")){ if($PSBoundParameters.ContainsKey("Server")){ $ret = New-ADGroup -Path $Projects -Server $Server -Name $ProjectName -GroupCategory Security -GroupScope Global -PassThru @@ -46,30 +54,22 @@ if($PSBoundParameters.ContainsKey("ProjectName")){ $member = $rs | Where-Object Name -Match ".*-RO" Add-ADGroupMember -Identity $target -Members $member } + + + $folder = New-Item -Path $projPath -ItemType Directory - $testFolder = Test-Path "$BaseDirectory+$ProjectName" -PathType Container + $ReadTarget = $acls | Where-Object Name -Match ".*RW" + $WriteTarget = $acls | Where-Object Name -Match ".*RO" - 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 + $Parameters = @{ + Name=$ProjectName + Path=$projPath } + $share = New-SmbShare @Parameters + $share|Set-SmbShare -FolderEnumerationMode AccessBased + + return $ret }