The script execution time is actually pretty immediate, to be honest. I’m probably going to put a small delay before reading the .log file, just to be sure.
I’m pasting the PowerShell script if anyone is ever going to need it.
# Execute with:
# powershell "& ""path_to_file\raid_status.ps1"""
# powershell -File "path_to_file\raid_status"
# Write to log file.
#
# Parameters
# $Mode: if true, Write-File will log system messages.
# $FilePath: output file path.
# $Timestamp: current timestamp.
# $Value: output value.
function Write-File {
param (
[Parameter(Mandatory=$true, Position=0)]
[bool]$Mode,
[Parameter(Mandatory=$true, Position=1)]
[string]$FilePath,
[string]$Timestamp,
[Parameter(Mandatory=$true, Position=3)]
[string]$Value
)
if ($Mode) {
Out-File -FilePath $FilePath -InputObject "[$Timestamp] $Value" -Append -Encoding ascii
}
else {
Out-File -FilePath $FilePath -InputObject $Value -Encoding ascii
}
}
# Log file path.
$LogFilePath = "$PSScriptRoot\storage_spaces.log"
# Status file path.
$StatusFilePath = "$PSScriptRoot\status.log"
# Current timestamp.
$Timestamp = Get-Date -Format "dd/MM/yyyy HH:mm:ss:fffffff K"
# Current physical disks' health status.
try {
$BadDisks = get-physicaldisk | Where-Object {$_.HealthStatus -ne "Healthy"}
}
catch {
$Message = "Command has failed: $($_.Exception.Message)"
Write-File $true $LogFilePath -Timestamp $Timestamp $Message
exit 1
}
if ($BadDisks) {
$Message = "Check diagnostics: possible disk failure. | $BadDisks"
Write-File $true $LogFilePath -Timestamp $Timestamp $Message
Write-File $false $StatusFilePath $false
return $false
}
else {
$Message = "Healthy: no physical disk issues found."
Write-File $true $LogFilePath -Timestamp $Timestamp $Message
Write-File $false $StatusFilePath $true
}
# Current status of virtual drives.
try {
$BadRAIDState = Get-VirtualDisk | where-object {$_.OperationalStatus -ne "OK"}
}
catch {
$Message = "Command has failed: $($_.Exception.Message)"
Write-File $true $LogFilePath -Timestamp $Timestamp $Message
exit 1
}
if ($BadRAIDState) {
$Message = "Check diagnostics: possible RAID system failure. | $BadRAIDState"
Write-File $true $LogFilePath -Timestamp $Timestamp $Message
Write-File $false $StatusFilePath $false
return $false
}
else {
$Message = "Healthy: no Windows Storage Spaces issues found."
Write-File $true $LogFilePath -Timestamp $Timestamp $Message
Write-File $false $StatusFilePath $true
return $true
}