Kit Ho
Kit Ho

Reputation: 26968

Powershell: How can i give permission to a folder with full control , on user "everyone"?

I have a folder

C:\TEMP

inside there is subfolder

C:\TEMP\a C:\TEMP\b and a file name apple.txt

how can I change all the permissions to Everyone with full control access using powershell script?

Thanks

Upvotes: 1

Views: 11874

Answers (2)

DYG
DYG

Reputation: 1

Thanks for your answer. I made some corrections and enhances (a keyword/expected pattern)

$user = "everyone"
$Folders = Get-childItem -Directory F:\SITE\
$InheritanceFlag = [System.Security.AccessControl.InheritanceFlags]::ContainerInherit -bor [System.Security.AccessControl.InheritanceFlags]::ObjectInherit
$PropagationFlag = [System.Security.AccessControl.PropagationFlags]::None
$objType = [System.Security.AccessControl.AccessControlType]::Allow 
$keyword = "PublicTempStorage"

$Folders | %{
    $Folder = $_

    $acl = Get-Acl $Folder.FullName
    $permission = $user,"Modify", $InheritanceFlag, $PropagationFlag, $objType
    $accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule $permission

    $acl.SetAccessRule($accessRule)
    if ($Folder -match $keyword) 
    {
        Set-Acl -AclObject $acl -Path $Folder.FullName
    }
} 

Upvotes: 0

David Brabant
David Brabant

Reputation: 43499

$user = "domain\user"
$Folders = Get-childItem c:\TEMP\
$InheritanceFlag = [System.Security.AccessControl.InheritanceFlags]::ContainerInherit -bor [System.Security.AccessControl.InheritanceFlags]::ObjectInherit
$PropagationFlag = [System.Security.AccessControl.PropagationFlags]::None
$objType = [System.Security.AccessControl.AccessControlType]::Allow 

$Folders | %{
    $Folder = $_

    $acl = Get-Acl $Folder
    $permission = $user,"Modify", $InheritanceFlag, $PropagationFlag, $objType
    $accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule $permission

    $acl.SetAccessRule($accessRule)
    Set-Acl $Folder $acl
} 

Upvotes: 5

Related Questions