WMI question
Posted: Wed Sep 19, 2018 12:40 am
Hello, can someone please assist with the following
I have the following script
which returns information about the disk drives on your computer (mostly from the internet with some bits added by me).
This works fine, however I need one more important piece of information added to the output and would be grateful for assistance with this
The above any returns disk drives where the disk type is 3 e.g. a fixed disk as opposed to a CD/DVD or USB drive.
I want the script to out put information on all drives on the system weather they are fixed disks, CD/DVD or USB and output the corresponding Drive Type
Thanks in advance
I have the following script
Code: Select all
function Get-DiskInfo {
[cmdletbinding()]
param ()
begin
{ $Array = New-Object -TypeName System.Collections.ArrayList }
process
{
try
{
$DiskInfo = [ordered]@{ }
$diskdrive = Get-WmiObject win32_diskdrive -ErrorAction Stop
foreach ($drive in $diskdrive)
{
$DiskInfo.DeviceID = $drive.deviceid.substring(4)
$DiskInfo.Model = $drive.model
$DiskInfo.Size = $drive.Size
$partitions = Get-WmiObject -Query "ASSOCIATORS OF {Win32_DiskDrive.DeviceID=`"$($drive.DeviceID.replace('\', '\\'))`"} WHERE AssocClass = Win32_DiskDriveToDiskPartition" -ErrorAction SilentlyContinue
foreach ($part in $partitions)
{
$DiskInfo.Partition = $part.name
$vols = Get-WmiObject -Query "ASSOCIATORS OF {Win32_DiskPartition.DeviceID=`"$($part.DeviceID)`"} WHERE AssocClass = Win32_LogicalDiskToPartition" -ErrorAction SilentlyContinue
foreach ($vol in $vols)
{
$DiskInfo.Volume = $vol.Name
$DiskInfo.DriveType = $vol.DriveType
[void]$Array.Add([PSCustomObject]$DiskInfo)
}
}
}
}
catch { return "Error collecting disk, partition and volume information the error was $($Error[0].Exception.Message)" }
}
end { return $Array }
}
which returns information about the disk drives on your computer (mostly from the internet with some bits added by me).
This works fine, however I need one more important piece of information added to the output and would be grateful for assistance with this
The above any returns disk drives where the disk type is 3 e.g. a fixed disk as opposed to a CD/DVD or USB drive.
I want the script to out put information on all drives on the system weather they are fixed disks, CD/DVD or USB and output the corresponding Drive Type
Thanks in advance