是否可以在平面旧wmic命令中执行此PowerShell脚本?如果可能的话,我需要根据路径或驱动器号获取磁盘模型信息,但是在运行PowerShell脚本时遇到问题。
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
}
}
}
}
在这个问题中分享了脚本: Combine `Get-Disk` info and `LogicalDisk` info in PowerShell?
答案 0 :(得分:2)
我不确定我理解:
wmic用于进行单一,简单的查询。
如果您想进行更复杂的查询(例如,上面的嵌套循环),您将需要某种“编程语言”。像C#,VBScript ......或Powershell。
问:尝试执行此脚本时遇到的“问题”究竟是什么?
以下是脚本的示例输出:
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:
另见PowerShell says "execution of scripts is disabled on this system."