-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfileinfo.ps1
67 lines (52 loc) · 1.79 KB
/
fileinfo.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
61
62
63
64
65
66
67
param (
[Parameter(
Mandatory=$true,
HelpMessage="Path to a file or some other Item.",
ValueFromPipeline=$true
)]
[String[]]
$Path
)
ForEach ($PathItem in $Path) {
$Item = Get-Item $PathItem
#
# File name
#
Write-Host -NoNewline -ForegroundColor Gray $Item.Parent
#Write-Host -NoNewline -ForegroundColor Gray ([IO.Path]::DirectorySeparatorChar)
if (Test-Path -Path $Item.FullName -PathType Container) {
# Path is a folder
Write-Host -NoNewline -ForegroundColor White $Item.BaseName
Write-Host -ForegroundColor Gray ([IO.Path]::DirectorySeparatorChar)
} else {
# Regular file
Write-Host -ForegroundColor White $Item.Name
}
#
# Mode
#
Write-Host -NoNewline -ForegroundColor Gray "Mode: "
Write-Host -ForegroundColor White $Item.Mode
Write-Host -NoNewline -ForegroundColor Gray "Attributes: "
Write-Host -ForegroundColor White $Item.Attributes
if (Test-Path -Path $Item -PathType Leaf) {
Write-Host -NoNewline -ForegroundColor Gray "Size: "
if ($Item.Length -lt 2MB) {
Write-Host -ForegroundColor White $Item.Length
} elseif ($Item.Length -lt 1MB) {
$size = "{0:n2}" -f ($Item.Length/1024)
Write-Host -ForegroundColor White "${size} KB"
} elseif ($Item.Length -lt 1GB) {
$size = "{0:n2}" -f ($Item.Length/(1024*1024))
Write-Host -ForegroundColor White "${size} MB"
} else {
$size = "{0:n2}" -f ($Item.Length/(1024*1024*1024))
Write-Host -ForegroundColor White "${size} GB"
}
}
Write-Host -NoNewline -ForegroundColor Gray "Last Access:"
Write-Host -ForegroundColor White $Item.LastAccessTime
if ($Path.Count -gt 1) {
Write-Host ""
}
}