2012-10-19 64 views
1

gwmi win32_volume爲我提供了該卷的詳細信息。從wmi找到卷的磁盤簽名?

gwmi win32_diskdrive爲我提供了磁盤簽名。

如何獲得磁盤簽名使用PowerShell特定卷GUID(卷的GUID這個樣子\\?\Volume{2e5e3ff7-fb5a-11e1-9924-80c16e6c465c}\

使用Win32_LogicalDisk是不是我的選擇,因爲有些卷可能無法安裝,以後也不會具有與其相關聯的信。很好的例子是System Reserved分區在Windows 7

+1

看到http://jrich523.wordpress.com/2011/12/12/using-wmi-to -link-a-disk-volume-to-a-physical-disk-with-powershell /#comment-336 –

回答

1

我無法找到任何與我的要求gwmi,所以我從powershell訪問diskpart。

在這種情況下,我獲取該gwmi win32_diskdrive會幫助磁盤簽名我獲得

$volumeCommand = "list volume" | diskpart 
$Pattern = 'XXXbbbXXXX' 
$Volume 
for($i=5; $i -le $volumeCommand.length; $i++) 
{ 
write-host $volumeCommand[$i] 
$matched = @(Select-String -inputobject $volumeCommand[$i] -Pattern $Pattern) 
    if($matched) { 
    $Volume=$volumeCommand[$i -1 ] 
    break 
    } 
} 

$columnToGet = 1 
$volumeName = $Volume | 
    %{ $_.Split(" ",[StringSplitOptions]"RemoveEmptyEntries")[$columnToGet] } 

$selectCommand = "sel volume " +$volumeName 
$uniqueid = "uniqueid disk" 
write-host $selectCommand 
$volumeuniqueidCommand = $selectCommand , $uniqueid | diskpart 
write-host $volumeuniqueidCommand 


$signature = $volumeuniqueidCommand[$volumeuniqueidCommand.length-3].trimStart("Disk ID: ") 
write-host $signature 
$signature = [CONVERT]::toint32($signature,16) 
write-host $signature 
0

我認爲最好的(也是唯一IMO)的方法是使用DiskExt.exe from Sysinternals

你可以使用PowerShell來解析DiskExt輸出連接nding相關的體積,然後使用win32_volume選擇他signature

0

你可能會尋找這個碼盤驅動:

$StrComputer = 'COMPUTER_NAME' 
$DeviceId = "X:" 
$wmiLogicalDiskQuery = "ASSOCIATORS OF {Win32_LogicalDisk.DeviceID='" + $DeviceId + "'} where AssocClass = Win32_LogicalDiskToPartition"; 
$PhysicaldiskPartitionName = (gwmi -Query $wmiLogicalDiskQuery).Name; 
$wmiPhysicalDiskQuery = "ASSOCIATORS OF {Win32_DiskPartition.DeviceID='" + $PhysicaldiskPartitionName + "'} where AssocClass = Win32_DiskDriveToDiskPartition"; 
$PhysicaldiskDriveName = (gwmi -Query $wmiPhysicalDiskQuery -Comp $StrComputer).DeviceID 
$DiskSignature = (gwmi Win32_DiskDrive -Comp $StrComputer | where-object {$_.DeviceID -eq $PhysicaldiskDriveName}).Signature 

這是從here略加修改。

+1

此聯繫人win32.logicaldisk與win32.diskdrive和win32.diskpartition有win32.volume –

+0

[不是音量與邏輯磁盤相同嗎?](http://en.wikipedia.org/wiki/Logical_disk) – Neolisk

+0

按體積來說,我的意思是win32_volume api這裏的設備ID是一個卷引導例如:\\?\ Volume {2e5e3ff7-fb5a -11e1-9924-80c16e6c465c} \而win32_diskdrive使用類似於//./的東西PHYISICALDRIVE2 ...單個磁盤驅動器可以有多個卷關聯 –