-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGet-FSOFolderSize.ps1
49 lines (37 loc) · 1.23 KB
/
Get-FSOFolderSize.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
#the folder size includes hidden files
Function Get-FSOFolderSize {
[cmdletbinding()]
[OutputType("PSCustomObject")]
param(
[Parameter(Position = 0, Mandatory, HelpMessage = "Enter a filesystem path like C:\Scripts. Do not specify a directory root.")]
[ValidateNotNullOrEmpty()]
[ValidateScript({$_ -notmatch '^[a-zA-Z]:\\$'})]
[string]$Path,
[ValidateNotnullorEmpty()]
[string]$Computername = $env:COMPUTERNAME
)
Write-Verbose "Starting $($MyInvocation.MyCommand)"
Write-Verbose "Measuring $path on $($computername.toUpper())"
Invoke-Command {
if (Test-Path $using:path) {
$fso = New-Object -ComObject Scripting.FileSystemObject
$fso.GetFolder($using:path)
}
else {
Write-Warning "Can't find $($using:path) on $env:computername"
}
} -computername $Computername |
Select-Object -Property @{Name="Computername";Expression={$_.pscomputername.toUpper()}},
Path,DateCreated,DateLastModified,Size,
@{Name="SizeMB";Expression={$_.size/1mb -as [int]}}
Write-Verbose "Ending $($MyInvocation.MyCommand)"
}
<#
PS C:\> Get-FSOFolderSize C:\scripts
Computername : BOVINE320
Path : C:\scripts
DateCreated : 7/31/2017 5:06:58 PM
DateLastModified : 10/5/2018 5:12:51 PM
Size : 859878325
SizeMB : 820
#>