forked from jdhitsolutions/PSScriptTools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDiskData.ps1
More file actions
41 lines (34 loc) · 1.3 KB
/
DiskData.ps1
File metadata and controls
41 lines (34 loc) · 1.3 KB
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
#requires -module PSScriptTools
Function Get-DiskData {
[cmdletbinding()]
Param(
[Parameter(ValueFromPipeline)]
[ValidateNotNullOrEmpty()]
[string]$Computername = $env:computername
)
Begin {
Write-Detail "Starting $($myinvocation.MyCommand)" -Prefix begin -NoDate | Write-Verbose
} #begin
Process {
Write-Detail "Processing $($computername.toUpper())" -Prefix process -NoDate | 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 -NoDate | 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 -NoDate | 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
#>