Sunday, 8 August 2010

Get-DriveInfo.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     This script gets and displays basic information about drives on a local system.  
  4. .DESCRIPTION 
  5.     This script uses the System.Io.DriveInfo's GetDrives method to get drive 
  6.     info which is then displayed.   This is a re-implementation of an MSDN 
  7.     sample. 
  8. .NOTES 
  9.     File Name  : Get-DriveInfo.ps1 
  10.     Author     : Thomas Lee - tfl@psp.co.uk 
  11.     Requires   : PowerShell Version 2.0 
  12. .LINK 
  13.     This script posted to: 
  14.         http://pshscripts.blogspot.com/2010/07/get-driveinfops1.html  
  15.     MSDN Sample posted at: 
  16.         http://msdn.microsoft.com/en-us/library/system.io.driveinfo.aspx 
  17.         http://msdn.microsoft.com/en-us/library/system.io.driveinfo.getdrives.aspx 
  18. .EXAMPLE 
  19.    PSH [C:\foo]: .\Get-DriveInfo.ps1' 
  20.    Drive C:\ 
  21.       File type: Fixed 
  22.       Volume label: 
  23.       File system: NTFS 
  24.       Available space to current user:           6.75 gb 
  25.       Total available space:                     6.75 gb 
  26.       Total size of drive:                     48.828 gb 
  27.    Drive D:\ 
  28.       File type: Fixed 
  29.       Volume label: 
  30.       File system: FAT32 
  31.       Available space to current user:           1.81 gb 
  32.       Total available space:                     1.81 gb 
  33.       Total size of drive:                      2.003 gb 
  34.       <ETC...> 
  35. #> 
  36.  
  37. # Get Drive Info 
  38. $allDrives = [system.Io.DriveInfo]::GetDrives() 
  39.  
  40. # Now display details 
  41. foreach ($d in $allDrives)  { 
  42.     "Drive {0}"        -f $d.Name 
  43.     "  File type: {0}" -f $d.DriveType 
  44.     if ($d.IsReady)  { 
  45.          "  Volume label: {0}" -f $d.VolumeLabel 
  46.          "  File system: {0}"  -f $d.DriveFormat 
  47.          $fs  = $d.AvailableFreeSpace/1gb 
  48.          $tfs = $d.TotalFreeSpace/1gb 
  49.          $TS  = $d.TotalSize/1gb 
  50.          "  Available space to current user:{0, 15:n2} gb" -f $fs 
  51.          "  Total available space:          {0, 15:n2} gb" -f $tfs 
  52.          "  Total size of drive:            {0, 15:n3} gb" -f $ts 
  53.     } 

No comments: