Created
July 31, 2015 05:50
-
-
Save poshcodebear/355156a6e5652f9ac2e4 to your computer and use it in GitHub Desktop.
File server permissions audit
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
$folder = "\\server\share" | |
$tempfile = "c:\temp\output.csv" | |
$items = Get-ChildItem $folder -Recurse -ErrorAction SilentlyContinue | |
foreach ($item in $items) { | |
try { | |
$obj_acl = get-acl $item.FullName -ErrorAction Stop | |
$acls = $obj_acl.access | where {($_.isinherited -eq $false) -and (($_.identityreference -like "Domain1\*") -or ($_.identityreference -like "Domain2\*"))} | |
} | |
catch { <#SilentlyContinue#> } | |
foreach ($acl in $acls) { | |
$props = @{'Path' = $item.PSParentPath.Split(':')[2]; | |
'Name' = $item.Name; | |
'Domain' = $acl.IdentityReference.Value.Split('\')[0]; | |
'ID' = $acl.IdentityReference.Value.Split('\')[1]; | |
'Rights' = $acl.FileSystemRights; | |
'AccessType' = $acl.AccessControlType} | |
$obj = New-Object -TypeName PSObject -Property $props | |
$obj | Export-Csv $tempfile -Append | |
} | |
} | |
$output = Import-Csv $tempfile |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment