forked from RyanC92/Powershell-Repository
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNTFSAccesss_Pit.ps1
44 lines (34 loc) · 2.2 KB
/
NTFSAccesss_Pit.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
#Made specifically for \\pitfile1\data
#Directory selection for report export
Function Get-FolderName($InitialDirectory)
{
[System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") | Out-Null
$OpenFolderDialog = New-Object System.Windows.Forms.FolderBrowserDialog
#$OpenFolderDialog.initialDirectory = $initialDirectory
#$OpenFileDialog.filter = "CSV (*.csv) | *.csv"
$OpenFolderDialog.ShowDialog() | Out-Null
$OpenFolderDialog.SelectedPath
}
Write-host "Select Your Export Directory" -ForegroundColor Yellow -BackgroundColor Black
#call to Get-Foldername function to select export directory
$Directory = Get-FolderName
Write-host "Export Directory of $Directory has been selected" -ForegroundColor Green -BackgroundColor Black
#GetNTFSaccess for Pitroot
Write-host "Getting NTFSAccess for \\pitfile1\Data" -ForegroundColor Yellow -BackgroundColor Black
$PitRoot = Get-NTFSAccess \\pitfile1\Data
$PitRoot | Export-csv "$($Directory)\Report_PitFile1_Data_DirPerms_$([DateTime]::Now.ToSTring("MM-dd-yyyy")).csv" -NoTypeInformation
Write-host "NTFS Permissions for $Directory have been exported" -ForegroundColor Green -BackgroundColor Black
Write-host "Getting Childitem list for \\Pitfile1\Data\, Recursion depth of 2, Directory only - This may take a few minutes" -ForegroundColor Yellow -BackgroundColor Black
#Designate the scan path
$SubDir = Get-Childitem -Path \\Pitfile1\Data\ -Directory -Recurse -Depth 2
Write-host "Childitem locations have been collected" -ForegroundColor Green -BackgroundColor Black
#Set value of 0 for progress bar
$i = 0
#Run foreach loop on the contents of Subdir with the Get-ntfsaccess command
ForEach ($subdirscan in $Subdir){
Write-progress -Activity "Reading NTFS Permissions" -CurrentOperation "$($subdirscan.name)" -Status "Processing $($Subdirscan.name): $i of $($Subdir.count)" -PercentComplete ($i/$($Subdir.name.count)*100);
#Get-ntfsaccess -Path "$($subdirscan.Fullname)"
Write-host "Exporting $($Subdirscan.name)" -ForegroundColor Green -BackgroundColor Black
Get-Ntfsaccess -path "$($subdirscan.Fullname)" | Export-csv "$($Directory)\Report_PitFile1_Data_DirPerms_$([DateTime]::Now.ToSTring("MM-dd-yyyy")).csv" -NoTypeInformation -Append
$i++
}