Is it possible to do this powershell script in plane old wmic commands? I need to get disk model info based off a path or drive letter if possible but am having issues running powershell scripts.
Get-WmiObject Win32_DiskDrive | % {
$disk = $_
$partitions = "ASSOCIATORS OF " +
"{Win32_DiskDrive.DeviceID='$($disk.DeviceID)'} " +
"WHERE AssocClass = Win32_DiskDriveToDiskPartition"
Get-WmiObject -Query $partitions | % {
$partition = $_
$drives = "ASSOCIATORS OF " +
"{Win32_DiskPartition.DeviceID='$($partition.DeviceID)'} " +
"WHERE AssocClass = Win32_LogicalDiskToPartition"
Get-WmiObject -Query $drives | % {
New-Object -Type PSCustomObject -Property @{
Disk = $disk.DeviceID
DiskSize = $disk.Size
DiskModel = $disk.Model
Partition = $partition.Name
RawSize = $partition.Size
DriveLetter = $_.DeviceID
VolumeName = $_.VolumeName
Size = $_.Size
FreeSpace = $_.FreeSpace
}
}
}
}
Script was shared in this question: Combine `Get-Disk` info and `LogicalDisk` info in PowerShell?
I'm not sure I understand:
wmic is for making single, simple queries.
If you want to make more sophisticated queries (for example, the nested loops above), you're going to need some kind of "programming language". Like C#, VBScript ... or Powershell.
Q: What exactly are the "problems" you've encountered trying to execute this script?
Here is sample output from your script:
d:\>powershell -ExecutionPolicy ByPass -File tmp.ps1
DiskSize : 128034708480
RawSize : 117894545408
FreeSpace : 44036825088
Disk : \\.\PHYSICALDRIVE1
DriveLetter : C:
DiskModel : SanDisk SD6SF1M128G
VolumeName : OS_Install
Size : 117894541312
Partition : Disk #1, Partition #2
DiskSize : 320070320640
RawSize : 320070836224
FreeSpace : 29038071808
Disk : \\.\PHYSICALDRIVE2
DriveLetter : E:
DiskModel : TOSHIBA External USB 3.0 USB Device
VolumeName : TOSHIBA EXT
Size : 320070832128
Partition : Disk #2, Partition #0
DiskSize : 1000202273280
RawSize : 734673240064
FreeSpace : 141853818880
Disk : \\.\PHYSICALDRIVE0
DriveLetter : D:
DiskModel : HGST HTS721010A9E630
VolumeName : Data
Size : 734673235968
Partition : Disk #0, Partition #0
PS:
See also PowerShell says "execution of scripts is disabled on this system."