ps/Modules/Alkami.DevOps.Inventory/Public/Get-FileSystemInventory.ps1
2023-05-30 22:51:22 -07:00

52 lines
2.3 KiB
PowerShell

function Get-FileSystemInventory {
<#
.SYNOPSIS
Returns an OrderedDictionary that Represents the FileSystem Inventory.
#>
[CmdletBinding()]
Param()
$logLead = (Get-LogLeadName);
$providerStopWatch = [System.Diagnostics.StopWatch]::StartNew()
$fileSystemDictionary = New-Object System.Collections.Specialized.OrderedDictionary
$fileSystemDetails = New-Object System.Collections.Specialized.OrderedDictionary
Set-Variable megaByteDivisor -Option Constant -Value 1048576
try {
Write-Verbose "$logLead : [$($providerStopWatch.Elapsed)] : Getting File System Details"
$diskInfo = Get-CIMInstance -Namespace "root\CIMV2" -Class Win32_LogicalDisk -Property DeviceID, Name, FileSystem, VolumeName, Size, FreeSpace
Write-Verbose "$logLead : [$($providerStopWatch.Elapsed)] : File System Details Retrieved"
foreach ($disk in $diskInfo) {
$deviceId = $disk.DeviceID
$fileSystemDetails[$deviceId] = New-Object System.Collections.Specialized.OrderedDictionary
$fileSystemDetails[$deviceId]['Mount'] = $disk.CimInstanceProperties['Name'].Value
$fileSystemDetails[$deviceId]['Type'] = ($disk.CimInstanceProperties['FileSystem'].Value)
$fileSystemDetails[$deviceId]['Name'] = $disk.CimInstanceProperties['VolumeName'].Value
$fileSystemDetails[$deviceId]['SizeMB'] = $disk.CimInstanceProperties['Size'].Value / $megaByteDivisor
$fileSystemDetails[$deviceId]['AvailableMB'] = $disk.CimInstanceProperties['FreeSpace'].Value / $megaByteDivisor
$fileSystemDetails[$deviceId]['UsedMB'] = $fileSystemDetails[$deviceId]['SizeMB'] - $fileSystemDetails[$deviceId]['AvailableMB']
$fileSystemDetails[$deviceId]['UsedPercent'] = `
if ($fileSystemDetails[$deviceId]['SizeMB'] -ne 0) {
[System.Math]::Round($fileSystemDetails[$deviceId]['UsedMB'] * 100 / $fileSystemDetails[$deviceId]['SizeMB'], 2)
} else {
0
}
}
} catch {
$fileSystemDetails["Error"] = $_.Exception.ToString()
}
$fileSystemDictionary.Add('FileSystem', $fileSystemDetails)
Write-Verbose "$logLead : [$($providerStopWatch.Elapsed)] : Provider Complete"
$providerStopWatch.Stop()
return $fileSystemDictionary
}