[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[系统增强] powershell 获取 磁盘信息

  1. Function zFormat_sizereadable() {
  2. param(
  3. [int64]$num
  4. )
  5. $unit =@("B","K","M","G","T")
  6. $i = 0
  7. while ($num -gt 1024 ) { $i++; $num = $num /1024 }
  8. return "{0} {1}" -f $num , $unit[$i]
  9. }
  10. function Init-Formatting()
  11. {
  12. $script:ftToTalSize = @{label="ToTalSize" ; expression={(zFormat_sizereadable($_.Size))} ; alignment = "right" }
  13. $script:ftAllocatedSize = @{label="Allocated" ; expression={zFormat_sizereadable($_.AllocatedSize)} ; alignment = "right" }
  14. $script:ftOffset = @{label="Offset" ; expression={ zFormat_sizereadable($_.Offset) } ; alignment = "right"}
  15. $script:ftdDisk = @{label="Disk" ; expression={$_.Number}}
  16. $script:ftdName = @{label="Name" ; expression={$_.FriendlyName}}
  17. $script:ftdBus = @{label="Bus" ; expression={$_.BusType}}
  18. $script:ftdMedia = @{label="Media" ; expression={$_.MediaType}}
  19. $script:ftdStyle = @{label="Style" ; expression={$_.PartitionStyle}}
  20. $script:ftpDisk = @{label="Disk" ; expression={$_.DiskNumber}}
  21. $script:ftpPart = @{label="Part" ; expression={$_.PartitionNumber}}
  22. $script:ftpPartType = @{label="PartType" ; expression={$_.Type}}
  23. $script:ftpLetter = @{label="Ltr" ; expression={$L = ($_.DriveLetter).tostring();if ($L -match "[B-Z]") {$L} else {"-"}} ; alignment = "right" }
  24. $script:ftpIsActive = @{label="Active" ; expression={ switch ($_.IsActive) { True {"A"} } } ; alignment ="center"}
  25. $script:ftpIsBoot = @{label="Boot" ; expression={ switch ($_.IsBoot) { True {"B"} } }}
  26. $script:ftpAB = @{label="A-B" ; expression={ switch ($_.IsActive) { True {"Active"} } ; switch ($_.IsBoot) { True {"Boot"} } }}
  27. $script:ftFSLabel = @{label="FSLabel" ; expression={"'" + $_.FSLabel + "'"} ; alignment = "left" }
  28. }
  29. function Get-DiskPartitions() {
  30. $diskPhy = @(Get-PhysicalDisk)
  31. $disk = @( get-disk | sort-object { $_.DiskNumber } )
  32. $disk | add-member -NotePropertyName "MediaType" -NotePropertyValue ""
  33. foreach ( $x in $diskPhy ) {
  34. $disk | Where-Object { if ($_.UniqueId -eq $x.UniqueId) {$_.MediaType = $x.MediaType} }
  35. }
  36. # $vol = @(Get-WmiObject win32_volume)
  37. $vol =@(get-volume)
  38. $part = @( Get-Partition | sort-object { $_.DiskNumber , $_.PartitionNumber } )
  39. $part | add-member -NotePropertyName "FSType" -NotePropertyValue ""
  40. $part | add-member -NotePropertyName "FSLabel" -NotePropertyValue ""
  41. $part | foreach-object {
  42. $pAccessPaths = $_.AccessPaths
  43. $v =  $vol | Where-Object { $pAccessPaths -contains $_.Path }
  44. if ( $v ) {
  45. $_.FSType = $v.FileSystem
  46. $_.FSLabel = $v.FileSystemLabel
  47. }
  48. }
  49. return $disk,$part
  50. }
  51. function List-DiskPartitions() {
  52. $disk | Format-Table $ftdDisk,$ftdBus,$ftdMedia,$ftdStyle,$ftToTalSize,$ftAllocatedSize,$ftdName
  53. $part | Format-Table $ftpDisk,$ftpPart,$ftpLetter,FSType,$ftToTalSize,$ftpPartType, $ftFSLabel #,$ftpIsActive,$ftOffset
  54. }
  55. Init-Formatting
  56. $disk,$part = Get-DiskPartitions
  57. List-DiskPartitions
  58. return
  59. $dpv = read-host "select disk,part or vol"
  60. $dpv = $dpv.trim()
  61. switch -Regex ($dpv)
  62. {
  63. '^([c-z])$' { $selvol = $matches[1] ; break }
  64. '(\d+)\D+(\d+)' { $seldisk = $matches[1] ; $selpart = $matches[2] ; break }
  65. }
  66. $part | where-object { ($_.DiskNumber -eq $seldisk -and $_.PartitionNumber -eq $selpart) -or ($_.DriveLetter -eq $selvol) } |
  67. Format-Table $ftpDisk,$ftpPart,$ftpLetter,$ftpIsActive,$ftToTalSize,FSType,ftFSLabel
复制代码

没有
Get-PhysicalDisk
get-disk
命令的系统用不了

TOP

bat批处理里面,如何调用代码并显示磁盘信息?谢谢

TOP

TOP

返回列表