wmic 可以获取路径或物理名称的模型信息吗?
Can wmic get model info of path or physical names?
是否可以在平面旧 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
}
}
}
}
此问题中共享了脚本:
我不确定我是否理解:
wmic 用于进行单个简单查询。
如果您想进行更复杂的查询(例如上面的嵌套循环),您将需要某种 "programming language"。比如 C#、VBScript ... 或 Powershell。
问:您在尝试执行此脚本时遇到的 "problems" 究竟是什么?
这是您脚本的示例输出:
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."
是否可以在平面旧 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
}
}
}
}
此问题中共享了脚本:
我不确定我是否理解:
wmic 用于进行单个简单查询。
如果您想进行更复杂的查询(例如上面的嵌套循环),您将需要某种 "programming language"。比如 C#、VBScript ... 或 Powershell。
问:您在尝试执行此脚本时遇到的 "problems" 究竟是什么?
这是您脚本的示例输出:
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."