-
Notifications
You must be signed in to change notification settings - Fork 1
/
PathVarPermCheck.ps1
45 lines (40 loc) · 1.38 KB
/
PathVarPermCheck.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
$groups = [System.Security.Principal.WindowsIdentity]::GetCurrent().Groups | ForEach-Object -Process { Write-Output $_.Translate([System.Security.Principal.NTAccount]) }
$userpath = $env:path
$path_array = $userpath.split(";")
$dtable = New-Object System.Data.DataTable
$dtable.Columns.Add("FolderPath", "System.String") | Out-Null
$dtable.Columns.Add("Access", "System.String") | Out-Null
Write-host "Current Path: "
$path_array
function CheckFolderAccess {
Param (
[String]$Folder
)
$User = $env:UserName
if (! $Folder -eq "" ) {
try {
$permission = (Get-Acl $Folder -ErrorAction Stop).Access | ?{$_.IdentityReference -match $User} | Select IdentityReference,FileSystemRights
If ($permission){
$Row = $dtable.NewRow()
$Row.FolderPath = $Folder
$Row.Access = $permission.FileSystemRights
$dtable.Rows.Add($Row)
} elseif (! $permission) {
$Row = $dtable.NewRow()
$Row.FolderPath = $Folder
$Row.Access = "NoWriteAccess"
$dtable.Rows.Add($Row)
}
}
catch {
$Row = $dtable.NewRow()
$Row.FolderPath = $Folder
$Row.Access = "FolderDoesNotExist"
$dtable.Rows.Add($Row)
}
}
}
foreach ($p in $path_array) {
CheckFolderAccess $p
}
$dtable | Format-Table