Peter Lewis
01/28/2025, 10:24 AMBenjamin Crill
01/28/2025, 1:08 PMJeremy Saunders
01/28/2025, 2:55 PMFunction Check-WriteCacheFreeSpace {
param (
[string]$computername = "$env:computername",
[string]$wcdrive = "D"
)
$results = @()
$ResultProps = @{
WCdrivefreespace = "N/A"
Output_For_HTML1 = "NEUTRAL"
Output_To_Log1 = $null
vdiskdifSize_inMB = "N/A"
Output_For_HTML2 = "NEUTRAL"
Output_To_Log2 = $null
}
Try {
$HardDisk = Get-WmiObject Win32_LogicalDisk -ComputerName $computername -ErrorAction Stop -Filter "DeviceID='${wcdrive}:'" | Select-Object Size,FreeSpace
If ($HardDisk -ne $null) {
$DiskTotalSize = $HardDisk.Size
$DiskFreeSpace = $HardDisk.FreeSpace
$CacheDiskGB=[Math]::Round(($DiskFreeSpace/1073741824),2)
$PercentageDS = (($DiskFreeSpace / $DiskTotalSize ) * 100)
$PercentageDS = "{0:N2}" -f $PercentageDS
If ([int]$PercentageDS -ge 15) {
$ResultProps.Output_To_Log1 = "WCdrivefreespace: Disk Free is normal [ $PercentageDS % ]"
$ResultProps.WCdrivefreespace = "$PercentageDS %"
$ResultProps.Output_For_HTML1 = "SUCCESS"
} ElseIf (([int]$PercentageDS -lt 15) -and ([int]$PercentageDS -ge 10)) {
$ResultProps.Output_To_Log1 = "WCdrivefreespace: Disk Free is Low [ $PercentageDS % ]"
$ResultProps.WCdrivefreespace = "$PercentageDS %"
$ResultProps.Output_For_HTML1 = "WARNING"
} ElseIf ([int]$PercentageDS -lt 10) {
$ResultProps.Output_To_Log1 = "WCdrivefreespace: Disk Free is Critical [ $PercentageDS % ]"
$ResultProps.WCdrivefreespace = "$PercentageDS %"
$ResultProps.Output_For_HTML1 = "ERROR"
} ElseIf ([int]$PercentageDS -eq 0) {
$ResultProps.Output_To_Log1 = "WCdrivefreespace: Disk Free test failed"
$ResultProps.WCdrivefreespace = "$PercentageDS %"
$ResultProps.Output_For_HTML1 = "ERROR"
} Else {
$ResultProps.Output_To_Log1 = "WCdrivefreespace: Disk Free is Critical [ $PercentageDS % ]"
$ResultProps.WCdrivefreespace = "$PercentageDS %"
$ResultProps.Output_For_HTML1 = "ERROR"
}
} Else {
#
}
}
Catch [system.exception] {
#$_.Exception.Message
}
$ErrorActionPreference = "stop"
Try {
If (Test-Path "filesystem::\\$computername\$wcdrive`$\vdiskdif.vhdx") {
$ResultProps.vdiskdifSize_inMB = (Get-ChildItem "\\$computername\$wcdrive`$\vdiskdif.vhdx").Length/1024/1024
$ResultProps.Output_To_Log2 = "vdiskdifSize: The `"vdiskdif.vhdx`" size is $($ResultProps.vdiskdifSize_inMB) MB"
} Else {
$ResultProps.Output_To_Log2 = "vdiskdifSize: The `"vdiskdif.vhdx`" file cannot be reached"
}
}
Catch [system.exception] {
#$_.Exception.Message
$ResultProps.Output_To_Log2 = "Unable to connect via UNC path"
}
$ErrorActionPreference = "Continue"
$results += New-Object PsObject -Property $ResultProps
return $results
}Jeremy Saunders
01/28/2025, 3:03 PMJeremy Saunders
01/29/2025, 12:47 AMMatt Sliva
01/31/2025, 2:27 AMjvitech
02/04/2025, 9:55 AMJeremy Saunders
02/05/2025, 2:42 AMYuhua Lu
02/05/2025, 7:14 AMSimon Graham
02/08/2025, 7:39 PMSimon Graham
02/08/2025, 7:39 PMJeremy Saunders
02/12/2025, 5:34 AMjvitech
02/12/2025, 11:07 AMSimon Graham
02/12/2025, 8:42 PMJeremy Saunders
02/13/2025, 5:23 AMjvitech
02/13/2025, 11:17 AMSimon Graham
02/14/2025, 2:47 PMjvitech
02/14/2025, 6:08 PM