# Copyright (c) 2026, R. W. Rodolico # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # # 1. Redistributions of source code must retain the above copyright notice, this # list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above copyright notice, # this list of conditions and the following disclaimer in the documentation # and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # windows_storage.ps1 # Fixed local disks (diskinfo.), sizes in KiB as Unix df. # Sensor contract: unix/sensors/Documentation/README.md; keys: Documentation/Spec.md 7.6 # Must stay Windows PowerShell 5.1 compatible and pure ASCII. # # Version 1.0.0 20261018 Claude # Initial version (bug 211, stage W2) Import-Module ([IO.Path]::Combine($PSScriptRoot, '..', 'lib', 'SysinfoSensor.psm1')) Test-SysinfoWindows Invoke-SysinfoSensor { if ($null -eq (Get-Command Get-CimInstance -ErrorAction SilentlyContinue)) { Exit-SysinfoSensor -Code $SYSINFO_EXIT_NOT_APPLICABLE -Message 'Get-CimInstance not available' } foreach ($disk in @(Get-CimInstance -ClassName Win32_LogicalDisk -Filter 'DriveType = 3' -ErrorAction Stop)) { $letter = [string]$disk.DeviceID if ($letter -eq '' -or $null -eq $disk.Size) { continue } $size = [math]::Floor([double]$disk.Size / 1024) $used = [math]::Floor(([double]$disk.Size - [double]$disk.FreeSpace) / 1024) Write-SysinfoFact -Path @('diskinfo', $letter, 'fstype') -Value $disk.FileSystem Write-SysinfoFact -Path @('diskinfo', $letter, 'size') -Value ([int64]$size) Write-SysinfoFact -Path @('diskinfo', $letter, 'used') -Value ([int64]$used) Write-SysinfoFact -Path @('diskinfo', $letter, 'mount') -Value ($letter + '\') } }