-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdirectorychecker.ps1
59 lines (51 loc) · 2.11 KB
/
directorychecker.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
'-------------------------------------------------------------------------------------------------'
' ee.DirectoryChecker (2020-11-07) '
' Exports all system information of each file/folder located at the specified path, to a CSV file '
' (format: "attributes","creation time","last write time","last access time","size","fullname") '
'-------------------------------------------------------------------------------------------------'
Set-ExecutionPolicy Unrestricted -Scope CurrentUser
$erroractionpreference = "SilentlyContinue"
Remove-Variable *
$erroractionpreference = "Continue"
$dtStartTime = Get-Date
$dirInput = $args[0]
if (![System.IO.Path]::IsPathRooted($dirInput))
{
Write-Host "Error! Specify the absolute path to the input directory"
Exit
}
else
{
$dirInput = $dirInput.Trim("\")
}
$dirInputFlat =
$dirInput.Split([System.IO.Path]::GetInvalidFileNameChars()) -Join("_") -Replace " ","_"
$dirCsv = (Get-Item $psscriptroot -ErrorAction SilentlyContinue).FullName + "\results"
$csvFileName = "$($dtStartTime.ToString('yyyyMMdd_HHmmss'))_$dirInputFlat.csv"
Write-Host "Get info about files and folders located at: $dirInput\"
Write-Host "CSV file name: $csvFileName"
Write-Host "Processing..."
if (Test-Path $dirInput)
{
$list = Get-ChildItem $dirInput -Force -Recurse -ErrorAction SilentlyContinue `
| Select Mode, CreationTime, LastWriteTime, LastAccessTime, Length, FullName
}
else
{
Write-Host "Error! Input directory not found"
Exit
}
try
{
New-Item $dirCsv -ItemType Directory -ErrorAction SilentlyContinue | Out-Null
$list | Export-Csv "$dirCsv\$csvFileName" -Encoding UTF8 -NoTypeInformation
}
catch
{
Write-Host "Error! Unable to write output CSV file"
Exit
}
$tsElapsed = ($(Get-Date) - $dtStartTime).TotalSeconds
$nItems = (Get-Content "$dirCsv\$csvFileName").Length - 1
Write-Host "Ready! Processed in $tsElapsed seconds, found $nItems files and folders"
'-------------------------------------------------------------------------------------------------'