-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget-objrights.ps1
52 lines (41 loc) · 1.54 KB
/
get-objrights.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
# get-objrights; verze 2018-06-11 1649; strachotao
# vypise opravneni na kazdem objektu do souboru $outfile
#
# pouziti
#
# vypise prava vsech objektu z adresare c:\temp
# .\soubory-prava.ps1 -dir c:\temp
#
# vypise prava objektu nalezici uzivateli *admin* (wildcard maska)
# .\soubory-prava.ps1 -dir c:\temp -user admin
#
Param (
[Parameter(Mandatory=$false)][string]$user="all",
[Parameter(Mandatory=$true)][string]$dir
)
$ErrorActionPreference = 'SilentlyContinue'
$tik = [System.DateTime]::Now.ToString("yyyyMMdd-HHmmss")
$outfile = "c:\temp\prava-$($user)-$($tik).csv"
Write-Progress -Activity "Nacitam seznam souboru..."
$dirList = Get-ChildItem "$dir" -Recurse -ErrorAction SilentlyContinue
$filesCount = $dirList.Length
$counter = 0
Add-Content -Path $outfile "adresar;uzivatel;pravo;typ;zdedeno"
function Writer() {
Add-Content -Path $outfile "$($file.fullname);$($item.IdentityReference);$($item.FileSystemRights);$($item.AccessControlType);$($item.IsInherited)"
}
foreach ($file in $dirList) {
Write-Progress -Activity "Nacitam opravneni" -status "$file" -percentComplete ($counter/$filesCount*100)
$Acl = (Get-Acl -Path $file.fullname -Verbose)
$rawData = $acl.GetAccessRules($true, $true, [System.Security.Principal.NTAccount])
foreach ($item in $rawData) {
if ($user -eq 'all') {
Writer
}
elseif ($($item.IdentityReference) -ilike "*$user*") {
Writer
}
}
$counter++
}
Write-Host "hotovo, vystup je v $outfile"