Last active
August 29, 2015 14:02
-
-
Save nvnivs/49219084ea7dd83dc7af to your computer and use it in GitHub Desktop.
Disables "Include inheritable permissions from this object's parent" to a given folder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.Synopsis | |
Recursively updates the version of AssemblyInfo.cs files | |
.Parameter baseDir | |
The root directory from which to recursively search for AssemblyInfo files | |
Defaults to the directory of the script. | |
.Link | |
https://gist.github.com/z0c | |
#> | |
param( | |
[Parameter(Position=0)] [string] $path = $(throw "missing -path param"), | |
[Parameter(Position=2)] [string] $allowed = '' | |
) | |
$ErrorActionPreference = "stop" | |
$allowedUsers = @() | |
foreach ($u in $allowed.Split(',')) { | |
if ($u.Contains('\')) { | |
$allowedUsers += $u.ToLowerInvariant() | |
} | |
else { | |
$allowedUsers += ($env:computername + "\" + $u).ToLowerInvariant() | |
} | |
} | |
$acl = Get-Item $path | Get-Acl | |
$modified = $false | |
$acl.Access | ? { | |
$allowedUsers -notcontains $_.IdentityReference.ToString().ToLowerInvariant() | |
} | % { | |
Write-Output "Removing access right of user " + $_.IdentityReference | |
$acl.RemoveAccessRule($_) | out-null | |
$modified = $true | |
} | |
if ($modified) { | |
$acl | Set-Acl | |
} | |
# Disable permission inheritance from parent object | |
$acl = Get-Item $path | Get-Acl | |
if (!$acl.AreAccessRulesProtected) { | |
$acl.SetAccessRuleProtection($true,$false) | |
$acl | Set-Acl | |
Write-Output "Disabled inheritable permissions" | |
} | |
else { | |
Write-Output "Inheritable permissions already disabled" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment