我找不到 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