Skip to content

Instantly share code, notes, and snippets.

@poshcodebear
Created July 31, 2015 05:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save poshcodebear/355156a6e5652f9ac2e4 to your computer and use it in GitHub Desktop.
Save poshcodebear/355156a6e5652f9ac2e4 to your computer and use it in GitHub Desktop.
File server permissions audit
$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