forked from jdhitsolutions/PSScriptTools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DiskData.ps1
42 lines (35 loc) · 1.34 KB
/
DiskData.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
#requires -version 5.1
#requires -module PSScriptTools
Function Get-DiskData {
[cmdletbinding()]
Param(
[Parameter(ValueFromPipeline)]
[ValidateNotNullOrEmpty()]
[string]$Computername = $env:computername
)
Begin {
Write-Detail "Starting $($myinvocation.MyCommand)" -Prefix BEGIN -Time | Write-Verbose
} #begin
Process {
Write-Detail "Processing $($computername.toUpper())" -Prefix PROCESS -Time | Write-Verbose
Try {
$data = Get-CimInstance -Class Win32_logicaldisk -Filter "DriveType=3" -ComputerName $Computername -ErrorAction Stop
$data | ForEach-Object {
Write-Detail "Calculating PctFree for $($_.DeviceID)" -Prefix PROCESS -Time | Write-Verbose
$_ | Add-Member -MemberType ScriptProperty -Name PctFree -Value { Format-Percent -Value $this.freespace -Total $this.size -Decimal 2 } -Force
}
$data
}
Catch {
Throw $_
}
} #process
End {
Write-Detail "Ending $($myinvocation.MyCommand)" -Prefix END -Time | Write-Verbose
} #end
}
# Get-DiskData -verbose | Select DeviceID,Size,PctFree
<#
$condition = [ordered]@{{$psitem.pctfree -le 40}='yellow'}
Get-DiskData | Select-object DeviceID,Size,FreeSpace,PctFree,SystemName | Out-ConditionalColor $condition
#>