i am currently trying to set permissions using PowerShell.
This is my code:
$Rights = [System.Security.AccessControl.FileSystemRights] "DeleteSubdirectoriesAndFiles, Write, ReadAndExecute, Synchronize"
$Access=[System.Security.AccessControl.AccessControlType]::Allow
$Inherit=[System.Security.AccessControl.InheritanceFlags]::ContainerInherit -bor [System.Security.AccessControl.InheritanceFlags]::ObjectInherit
$Prop=[System.Security.AccessControl.PropagationFlags]::None
$DirPath = "\\CENSOREDDIR" + $ComboBox1.SelectedItem + "\" + $TextBox1.Text
Write-Host $DirPath
New-Item $DirPath -ItemType Directory
$GroupPath = $GruppenHT[$ComboBox1.SelectedItem]
$GroupPathFull = "RES-" + $GroupPath + "-L-C"
Write-Host "Group:"$GroupPathFull
$AccessRule = new-object System.Security.AccessControl.FileSystemAccessRule $GroupPathFull,$Rights,$Inherit,$Prop,$Access
Write-Host "AccessRule:"$AccessRule
$ACL = Get-ACL $DirPath
Write-Host "DIR:"$DirPath
$ACL.AddAccessRule($AccessRule)
Write-Host "Permissions:"$ACL.Access
This is what the Output for debugging looks like:
Group: RES-CENSOREDGROUP-L-C <-- CORRECT
AccessRule: System.Security.AccessControl.FileSystemAccessRule
DIR: \\CENSOREDDIR\test <-- CORRECT
Permissions: System.Security.AccessControl.FileSystemAccessRule System.Security.AccessControl.FileSystemAccessRule System.Security.AccessControl.FileSystemAccessRule S
ystem.Security.AccessControl.FileSystemAccessRule System.Security.AccessControl.FileSystemAccessRule System.Security.AccessControl.FileSystemAccessRule System.Security
.AccessControl.FileSystemAccessRule System.Security.AccessControl.FileSystemAccessRule
But nothing happens at all. No error is displayed, but the permission is not on the directory.
I also find it a bit strange that the variables are no longer available after the execution of the script. This is actually always the case in PowerShell ISE?
Is it because the whole thing is in a "Button_Click" event?
Maybe someone knows what to do.