在PowerShell中,我想將drivetype
(這裏是類型2)的驅動器(deviceid
)寫入數組(變量$letters
)。該driveletters應該被排序是這樣的:
$信= @(「A」,「B」)等將磁盤類型的deviceids寫入數組
下面我發現罰款win32_diskdrive
的作品,但我不能添加DRIVETYPE線。
$letters = Get-WmiObject win32_diskdrive |
Where {$_.interfacetype -Like "USB"} |
ForEach {Get-WmiObject -Query "ASSOCIATORS OF {Win32_DiskDrive.DeviceID=`"$($_.DeviceID.replace('\','\\'))`"} WHERE AssocClass = Win32_DiskDriveToDiskPartition"} |
ForEach {Get-WmiObject -Query "ASSOCIATORS OF {Win32_DiskPartition.DeviceID=`"$($_.DeviceID)`"} WHERE AssocClass = Win32_LogicalDiskToPartition"} |
ForEach {$_.deviceid}
下面的下一行包含Win32_LogicalDisk
代替win32_diskdrive
,但我沒能得到一個乾淨的陣列輸出像$letters = @("a:", "b:")
$letters = Get-WMIObject Win32_LogicalDisk -filter DriveType=2 | Select ($_.deviceid)
給
\\WIN7\root\cimv2:Win32_LogicalDisk.DeviceID="H:"
我怎麼能結合drivetype
與win32_diskdrive
或我怎麼能得到只有「H:」Win32_LogicalDisk
?
謝謝,它與你的提示很好地結合在一起 $ letters = Get-WMIObject Win32_LogicalDisk -filter DriveType = 2 |選擇 - 屬性設備ID 現在我發現它顯示也彈出,但仍然插入驅動器。如何只顯示具有(分區)大小的設備? – scriptinghomer 2014-11-23 19:27:15
好的,通過myselfe找到答案:Get-WMIObject Win32_LogicalDisk -filter DriveType = 2 |選擇-Property deviceid,size |其中{$ _。size} – scriptinghomer 2014-11-23 19:34:13
@scriptinghomer查看我的更新。 – Matt 2014-11-24 15:03:05