Sunday 18 July 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. .EXAMPLE 
  18.    PSH [C:\foo]: .\Get-Driveinfo.ps1 
  19.    Drive C:\ 
  20.       File type: Fixed 
  21.       Volume label: 
  22.       File system: NTFS 
  23.       Available space to current user:           6.75 gb 
  24.       Total available space:                     6.75 gb 
  25.       Total size of drive:                     48.828 gb 
  26.    Drive D:\ 
  27.       File type: Fixed 
  28.       Volume label: 
  29.       File system: FAT32 
  30.       Available space to current user:           1.81 gb 
  31.       Total available space:                     1.81 gb 
  32.       Total size of drive:                      2.003 gb 
  33.       <ETC...> 
  34. #> 
  35.  
  36. # Get Drive Info 
  37. $allDrives = [system.IO.DriveInfo]::GetDrives() 
  38.  
  39. # Now display details 
  40. foreach ($d in $allDrives)  { 
  41.     "Drive {0}" -f $d.Name 
  42.      "  File type: {0}" -f $d.DriveType 
  43.     if ($d.IsReady)  { 
  44.          "  Volume label: {0}" -f $d.VolumeLabel 
  45.          "  File system: {0}"  -f $d.DriveFormat 
  46.          $fs  = $d.AvailableFreeSpace/1gb 
  47.          $tfs = $d.TotalFreeSpace/1gb 
  48.          $TS  = $d.TotalSize/1gb 
  49.          "  Available space to current user:{0, 15:n2} gb" -f $fs 
  50.          "  Total available space:          {0, 15:n2} gb" -f $tfs 
  51.          "  Total size of drive:            {0, 15:n3} gb" -f $ts 
  52.     } 

No comments: