Navester
12/11/2025, 5:11 AMJerry Way
12/12/2025, 9:20 PMFacter.add(:win_storage_pws) do
confine osfamily: 'windows'
setcode do
def bytes_to_gbs (bytes) # creates a bytes to Gigabytes function
(bytes.to_f / 1000000000).round(2)
end
# This is the PowerShell call to retrieve the Storage info
storage = Facter::Core::Execution.execute("C:/Windows/system32/Windowspowershell/v1.0/powershell.exe -command \"Get-CimInstance -Classname win32_logicaldisk | ConvertTo-Json\"")
storage = JSON.parse(storage)
storage.reduce({}) do |result,volume|
if volume['FreeSpace'] && volume['Size']
percentage_free = (volume['FreeSpace'].to_f*100/volume['Size'].to_f).round(2) #Calculate free space %
end
# Setup the facts for display
properties = {
'size_gb' => bytes_to_gbs(volume['Size']),
'freespace_gb' => bytes_to_gbs(volume['FreeSpace']),
'drive_type' => volume['DriveType'],
'percentage_free' => percentage_free
}
result.merge ({volume['Name'] => properties})
end
end
end