Saturday, February 14, 2015

Powershell to add Read permission on all files in a directory

Recently I needed to update all the files in a specific directory, adding Read permission for the "Users" NTFS group.  Here is a Powershell script to do that.  It can be easily modified to update other users/groups or different permission sets.

$base = "C:\somefolder"
$files = get-childitem $base
foreach ($file in $files) {
    $Acl = Get-Acl $file.FullName
    $Ar = New-Object  system.security.accesscontrol.filesystemaccessrule("Users","Read","Allow")
    $Acl.SetAccessRule($Ar)
    Set-Acl $file.FullName $Acl
}

No comments:

Can't RDP? How to enable / disable virtual machine firewall for Azure VM

Oh no!  I accidentally blocked the RDP port on an Azure virtual machine which resulted in not being able to log into the VM anymore.  I did ...