Powershell获取磁盘信息

使用Powershell完成系统管理实在是太方便了,磁盘信息获取只需几行代码即可。
   1:  $DiskCount = ((Get-WmiObject -Class Win32_DiskDrive).Caption).count
   2:  #获取磁盘分区大小
   3:  $DiskInfo = Get-WmiObject -Class Win32_LogicalDisk 
   4:  echo "--------------------统计磁盘分区状况-------------------------"
   5:  echo "    驱动器号    卷标    分区空间    可用空间    文件系统    "        
   6:  foreach ($Drivers in $DiskInfo) 
   7:  {
   8:      $PartitionID = $Drivers.DeviceID
   9:      $PartitionSize = "{0:N2}GB" -f ($Drivers.Size/1GB)
  10:      $PartitionFreeSize = "{0:N2}GB" -f ($Drivers.FreeSpace/1GB)
  11:      $PartitionName = $Drivers.VolumeName
  12:      $PartitionFS = $Drivers.FileSystem
  13:      echo "    $PartitionID        $PartitionName    $PartitionSize        $PartitionFreeSize        $PartitionFS    "    
  14:  }
 

image

posted @ 2013-08-25 16:46  motools  阅读(3978)  评论(0编辑  收藏  举报