Powershell, need to create script to allow all users modify rightd to two folders in Program Files (x86) and ProgramData
Answers (2)
Create and change permission via Powershell
clear
$FolderPath = 'C:\Temp'
$UserList = 'Users'#,'Everyone'
If(!(Test-Path $FolderPath -PathType Container)) {
New-Item -Path $FolderPath -ItemType Directory
Foreach ($Users in $UserList) {
$ACL = Get-Acl -Path $FolderPath
$isProtected = $true
$preserveinheritance = $true
$acl.SetAccessRuleProtection($isProtected, $PreserveInheritance)
$rule=New-Object System.Security.AccessControl.FileSystemAccessRule("users","Modify,Synchronize","ContainerInherit, ObjectInherit","None","Allow")
$rule.IdentityReference.Translate([System.Security.Principal.securityidentifier])
$acl.SetAccessRule($rule)
Set-Acl -path $FolderPath -aclObject $ACL
}
} else {
write-host "-- Folder already created"
}
foreach ($dir in $dirs){
If (-Not (Test-Path $Dir)){ New-Item $dir -itemtype directory}
...
...