#Dmitry Trukhanov 2017.06.17 #Quick storage audit #Usage GetStorage.ps1 filename.htm [-Server servername] #filename - path to file to save report to #servername - optional parameter to collect information remotely, if omitted localhost will be used #you need to have administrator rights to collect advanced information and mount points, other way simple info will be collected param( [string] $Server, [Parameter(Mandatory = $true, Position = 0)] [string] $File ) if($Server -eq ""){ $Server='localhost' } $html = '' $html += '' $html += '' $html += 'Storage report' $html += @" "@ $html += '' $msftexception="" try{ $msftP2Vs = Get-WmiObject -ComputerName $Server -Query "Select * from MSFT_PartitionToVolume" -Namespace root\microsoft\windows\storage -ErrorAction Stop } Catch { $msftexception = $_.Exception.Message } $html += '' $html += '' $html += '' $html += '' $html += '' if($msftexception -eq ""){ $html += '' }else{ $html += '' } $html += '' $physicaldisks = Get-WmiObject -ComputerName $Server -Class Win32_DiskDrive foreach($physicaldisk in $physicaldisks){ $partitions = Get-WmiObject -ComputerName $Server -Query "ASSOCIATORS OF {Win32_DiskDrive.DeviceID='$($physicaldisk.DeviceID)'} WHERE AssocClass = Win32_DiskDriveToDiskPartition" $html += "" $num=0 foreach($partition in $partitions){ if($num -eq 0){ $html += '' $html += '' $num++ } } $html += '
Physical DrivePartitionsVolumesLogical Disks*
" $html += "Name: " + $physicaldisk.Name $html += "
" $html += "Model: " + $physicaldisk.Model $html += "
" $html += "Interface: " + $physicaldisk.InterfaceType $html += "
" $html += "Serial: " + $physicaldisk.SerialNumber $html += "
" $html += "Status: " + $physicaldisk.Status $html += "
" $html += "Size in GB: " + [Math]::Round($physicaldisk.Size/1GB) $html += "
' }else{ $html += '
' } $html += "Name: " + $partition.Name $html += "
" $html += "BootPartition: " + $partition.BootPartition $html += "
" $html += "Type: " + $partition.Type $html += "
" $html += "Size in GB: " + [Math]::Round($partition.Size/1GB) $html += '
' if($msftexception -eq ""){ $msftphysicaldisk = Get-WmiObject -ComputerName $Server -Query "Select * from MSFT_Disk where SerialNumber='$($physicaldisk.SerialNumber)'" -Namespace root\microsoft\windows\storage $msftpartition = Get-WmiObject -ComputerName $Server -Query "Select * from MSFT_Partition Where DiskNumber='$($msftphysicaldisk.Number)' AND Offset='$($partition.StartingOffset)'" -Namespace root\microsoft\windows\storage $msftvol = $null foreach($msftP2V in $msftP2Vs){ if($msftP2V.Partition -eq '\\.\ROOT\microsoft\windows\storage:'+$msftpartition.__RELPATH){ $msftvol=$msftP2V.Volume.Substring(57,53) } } $volume = Get-WmiObject -ComputerName $Server -Query "Select * from win32_volume where DeviceId='$($msftvol)'" if($volume -ne $null){ $html += 'Name: '+$volume.Name $html += "
" $html += 'Label: '+$volume.Label $html += "
" switch ($volume.DriveType) { 0 {$drivetypetext = "Unknown"} 1 {$drivetypetext = "No Root Directory"} 2 {$drivetypetext = "Removable Disk"} 3 {$drivetypetext = "Local Disk"} 4 {$drivetypetext = "Network Drive"} 5 {$drivetypetext = "Compact Disk"} 6 {$drivetypetext = "RAM Disk"} } $html += 'DriveType: '+$drivetypetext $html += "
" $html += 'Capacity in GB: '+[Math]::Round($volume.Capacity/1GB) $html += "
" $html += 'FreeSpace in GB: '+[Math]::Round($volume.FreeSpace/1GB) $html += "
" $html += 'FileSystem: '+$volume.FileSystem $html += "
" $html += 'BlockSize: '+$volume.BlockSize $html += "
" $html += 'Automount: '+$volume.Automount $html += "
" $html += 'Compressed: '+$volume.Compressed $html += "
" $html += 'PageFilePresent: '+$volume.PageFilePresent $html += "
" $html += 'IndexingEnabled: '+$volume.IndexingEnabled $html += "
" $html += 'QuotasEnabled: '+$volume.QuotasEnabled }else{ $html += "No volume for this partition" } }else{ $logicaldrive = Get-WmiObject -ComputerName $Server -Query "ASSOCIATORS OF {Win32_DiskPartition.DeviceID='$($partition.DeviceID)'} WHERE AssocClass = Win32_LogicalDiskToPartition" if($logicaldrive -ne $null){ $html += 'Name: ' + $logicaldrive.Name $html += "
" $html += 'FileSystem: ' + $logicaldrive.FileSystem $html += "
" $html += 'Free Space in GB: ' + [Math]::Round($logicaldrive.FreeSpace/1GB) $html += "
" $html += 'Size in GB: ' + [Math]::Round($logicaldrive.Size/1GB) }else{ $html += 'No logical drive on this partition' } } $html += '
' if($msftexception -ne ""){ $html += "
* Could not get information from MSFT_PartitionToVolume, try to run script as Administrator
Exception: '$($msftexception)'
" } $html += '' $html += '' Set-Content $File $html