-
Notifications
You must be signed in to change notification settings - Fork 0
/
DFSPermissions.ps1
60 lines (41 loc) · 1.35 KB
/
DFSPermissions.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#Powershell script to retrieve permissions of specific network shares and diffs them. Then outputs to CSV for Splunk
#BLieberman , 6/30/14
####SANITZIED###
#paths have been replaced with placeholder variables
#Setup array with our paths
$PathArray= @("$path1", "$path2", "$pathx")
#need this because having slashes in filenames is bad
$iter=0
foreach ($path in $PathArray)
{
$previous="$dir_" + $iter + ".csv"
$current="$dir_" + $iter + ".csv"
#if "init" is passed as param, init the previous file and quit
if($args[0] -eq "init")
{
Get-Acl -path $path | Select-Object -ExpandProperty Access | export-csv -notype $previous
Write-Host "Initialized!"
$iter += 1
continue
}
#get updates
Get-Acl -path $path | Select-Object -ExpandProperty Access | export-csv -notype $current
#check difs
$dif = Compare-Object -ReferenceObject (Get-Content $previous) -DifferenceObject (Get-Content $current) -IncludeEqual
#output to file, detect add/remove
foreach ($difference in $dif)
{
if($difference.SideIndicator -eq "=>")
{
$difference.InputObject + ",`"Add`"" + ",`"$path`"" >> $dir\output\diffs.csv
}
if($difference.SideIndicator -eq "<=")
{
$difference.InputObject + ",`"Remove`"" + ",`"$path`"" >> $dir\output\diffs.csv
}
}
#move current to previous and delete previous
Remove-Item $previous
Rename-Item $current $previous
$iter += 1
}