您现在的位置是: 网站首页 >系统软件 系统软件

Powershell获取硬盘信息及对应的S.M.A.R.T.数据集

admin2019年7月18日 20:43 Powershell | Windows 3331人已围观

# Powershell命令查询 ```powershell PS C:\WINDOWS\system32> $s=(Get-WmiObject -Class MSStorageDriver_ATAPISmartData -Namespace 'root/wmi').VendorSpecific PS C:\WINDOWS\system32> $s.GetType() IsPublic IsSerial Name BaseType -------- -------- ---- -------- True True Byte[] System.Array PS C:\WINDOWS\system32> $s -join ',' 10,0,1,15,0,66,63,54,2,61,0,0,0,0,3,3,0,97,96,0,0,0,0,0,0,0,4,50,0,100,100,35,0,0,0,0,0,0,5,51,0,100,100,0,0,0,0,0,0,0,7,15,0,76,60,107,162,128,2,0,0,0,9,50,0,92,92,1,30,0,0,0,0,0,10,19,0,100,100,0,0,0,0,0,0,0,12,50,0,100,100,23,0,0,0,0,0,0,183,50,0,100,100,0,0,0,0,0,0,0,184,50,0,100,100,0,0,0,0,0,0,0,187,50,0,100,100,0,0,0,0,0,0,0,188,50,0,100,100,0,0,0,0,0,0,0,189,58,0,100,100,0,0,0,0,0,0,0,190,34,0,59,52,41,0,26,44,0,0,0,193,50,0,100,100,93,1,0,0,0,0,0,194,34,0,41,23,41,0,0,0,23,0,0,195,26,0,1,1,54,2,61,0,0,0,0,197,18,0,100,100,0,0,0,0,0,0,0,198,16,0,100,100,0,0,0,0,0,0,0,199,62,0,200,200,0,0,0,0,0,0,0,240,0,0,100,253,212,29,0,0,231,240,36,241,0,0,100,253,253,88,196,83,0,0,0,242,0,0,100,253,171,28,117,209,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 PS C:\WINDOWS\system32> Get-WmiObject -Class MSStorageDriver_ATAPISmartData -Namespace 'root/wmi' __GENUS : 2 __CLASS : MSStorageDriver_ATAPISmartData __SUPERCLASS : MSStorageDriver __DYNASTY : MSStorageDriver __RELPATH : MSStorageDriver_ATAPISmartData.InstanceName="SCSI\\Disk&Ven_ST1000DM&Prod_010-2EP102\\4&2ca40c3&0&000200_0" __PROPERTY_COUNT : 17 __DERIVATION : {MSStorageDriver} __SERVER : LR-PC __NAMESPACE : root\wmi __PATH : \\LR-PC\root\wmi:MSStorageDriver_ATAPISmartData.InstanceName="SCSI\\Disk&Ven_ST1000DM&Prod_010-2EP102\\4&2ca40c3&0&000200_0" Active : True Checksum : 13 ErrorLogCapability : 1 ExtendedPollTimeInMinutes : 104 InstanceName : SCSI\Disk&Ven_ST1000DM&Prod_010-2EP102\4&2ca40c3&0&000200_0 Length : 512 OfflineCollectCapability : 115 OfflineCollectionStatus : 0 Reserved : {2, 0, 0, 0...} SelfTestStatus : 0 ShortPollTimeInMinutes : 1 SmartCapability : 3 TotalTime : 0 VendorSpecific : {10, 0, 1, 15...} VendorSpecific2 : 0 VendorSpecific3 : 0 VendorSpecific4 : {0, 0, 200, 7...} PSComputerName : LR-PC PS C:\WINDOWS\system32> (Get-WmiObject -Class MSStorageDriver_ATAPISmartData -Namespace 'root/wmi').InstanceName SCSI\Disk&Ven_ST1000DM&Prod_010-2EP102\4&2ca40c3&0&000200_0 PS C:\WINDOWS\system32> Get-WmiObject -Class Win32_DiskDrive Partitions : 1 DeviceID : \\.\PHYSICALDRIVE1 Model : ST1000DM010-2EP102 Size : 1000202273280 Caption : ST1000DM010-2EP102 Partitions : 3 DeviceID : \\.\PHYSICALDRIVE0 Model : FORESEE P900F128GB Size : 128034708480 Caption : FORESEE P900F128GB ``` # Powershell获取硬盘信息及SMART信息 优先从`Win32_DiskDrive`获取硬盘的信号,大小及`PNPDeviceID` 在获取硬盘的`MSStorageDriver_ATAPISmartData`中的`InstanceName`对应`PNPDeviceID`来匹配硬盘的SMART数据 ```powershell $res = @{} # 定义哈希 # 获取硬盘的相关信息 $objs = gwmi Win32_DiskDrive -Namespace 'root/cimv2' foreach ($obj in $objs) { $tmp = @{} # 说明 $Caption = $obj.Caption #echo $Caption # 型号 $Model = $obj.Model #echo $Model $tmp['Model'] = $Model # 这个字段和硬盘SMART中的InstanceName对应 $PNPDeviceID = $obj.PNPDeviceID #echo $PNPDeviceID $tmp['PNPDeviceID'] = $PNPDeviceID # 大小 $Size = $obj.Size #echo $Size $Capacity = "{0:N2}G" -f ($Size / 1073741824) $tmp['Capacity '] = $Capacity $Size = "{0:N0}G" -f ($Size / 1000000000) $tmp['Size'] = $Size #echo $tmp $res[$Model] = $tmp } #echo $res # 获取硬盘SMART信息 $objs = Get-WmiObject -Class MSStorageDriver_ATAPISmartData -Namespace 'root/wmi' # $objs = gwmi MSStorageDriver_ATAPISmartData -Namespace 'root/wmi' foreach ($obj in $objs) { # 这个字段可以和硬盘信息中的PNPDeviceID对应 $InstanceName = $obj.InstanceName #echo $InstanceName # SMART $VendorSpecific = $obj.VendorSpecific # echo $VendorSpecific # echo $VendorSpecific.GetType() $VendorSpecific = $VendorSpecific -join ',' #echo $VendorSpecific foreach($key in $res.Keys) { #echo $res[$key].PNPDeviceID #echo $InstanceName if( $InstanceName -like $res[$key].PNPDeviceID + '*') # 判断包含,对大小写不敏感 { $res[$key]['SMART'] = $VendorSpecific } } } echo $res echo '' foreach ($key in $res.Keys) { echo $res[$key] echo '' } ``` 运行后得到的结果 ``` Name Value ---- ----- ST1000DM010-2EP102 {Capacity , Size, SMART, Model...} FORESEE P900F128GB {Capacity , Size, Model, PNPDeviceID} Capacity 931.51G Size 1,000G SMART 10,0,1,15,0,67,63,155,52,86,0,0,0,0,3,3,0,97,96,0,0,0,0,0,0,0,4,50,0,100,100,35,0,0,0,0,0,0,5,51,0,100,100,0,0,0,0,0,0,0,7,15,0,76,60,152,24,129,2,0,0,0,9,50,0,92,92,7,30... Model ST1000DM010-2EP102 PNPDeviceID SCSI\DISK&VEN_ST1000DM&PROD_010-2EP102\4&2CA40C3&0&000200 Capacity 119.24G Size 128G Model FORESEE P900F128GB PNPDeviceID SCSI\DISK&VEN_NVME&PROD_FORESEE_P900F128\5&6B06F81&0&000000 ```

很赞哦! (2)

文章交流

  • emoji
0人参与,0条评论

当前用户

未登录,点击   登录

站点信息

  • 建站时间:网站已运行2300天
  • 系统信息:Linux
  • 后台程序:Python: 3.8.10
  • 网站框架:Django: 3.2.6
  • 文章统计:257 篇
  • 文章评论:63 条
  • 腾讯分析网站概况-腾讯分析
  • 百度统计网站概况-百度统计
  • 公众号:微信扫描二维码,关注我们
  • QQ群:QQ加群,下载网站的学习源码
返回
顶部
标题 换行 登录
网站