Powershell to pull mount point disk details


posted by Krishna
12-16-2009

Downloads: 977
File size: 2.8kB
Views: 6,876

Embed
Powershell to pull mount point disk details
  1. #Get-MountPointInfo.PS1 Script 
  2. #Eric Woodford 
  3. #Scripts@ericwoodford.com 
  4. #Nov 11, 2008 
  5. #Discover and detail volume mount points on a specified Windows server. 
  6. # 
  7.  
  8. function Get-MountPointInfo($ServerName) { 
  9.         $Summary = @() 
  10.         
  11.         $objFSO = New-Object -com Scripting.FileSystemObject 
  12.         $MountPoints = gwmi -class "win32_mountpoint" -namespace "root\cimv2" -computername $ServerName 
  13.         $Volumes = gwmi -class "win32_volume" -namespace "root/cimv2" -ComputerName $ServerName| select name, freespace 
  14.  
  15.  
  16.         foreach ($MP in $Mountpoints) { 
  17.                 $MP.directory = $MP.directory.replace("\\","\")         
  18.                 foreach ($v in $Volumes) { 
  19.                         $vshort = $v.name.Substring(0,$v.name.length-1 ) 
  20.                         $vshort = """$vshort""" #Make it look like format in $MP (line 11). 
  21.                         if ($mp.directory.contains($vshort)) { #only queries mountpoints that exist as drive volumes no system 
  22.                                 $Record = new-Object -typename System.Object 
  23.                                 $DestFolder = "\\"+$ServerName + "\"+ $v.name.Substring(0,$v.name.length-1 ).Replace(":","$"
  24.                                 #$destFolder #troubleshooting string to verify building dest folder correctly. 
  25.                                 $colItems = (Get-ChildItem $destfolder |  where{$_.length -ne $null} |Measure-Object -property length -sum
  26.                                 #to clean up errors when folder contains no files. 
  27.                                 #does not take into account subfolders. 
  28.                                 
  29.                                 if($colItems.sum -eq $null) { 
  30.                                         $fsize =
  31.                                 } else
  32.                                         $fsize = $colItems.sum 
  33.                                 
  34.                                 
  35.                                 $TotFolderSize = $fsize + $v.freespace 
  36.                                 $percFree = "{0:P0}" -f ( $v.freespace/$TotFolderSize
  37.                                 $Record | add-Member -memberType noteProperty -name Name -Value $V.name 
  38.                                 $Record | add-Member -memberType noteProperty -name FileSize -Value $fsize 
  39.                                 $Record | add-Member -memberType noteProperty -name FreeSpace -Value $v.freespace 
  40.                                 $Record | add-Member -memberType noteProperty -name PercFree -Value $percFree 
  41.                                 $Summary += $Record 
  42.                         
  43.                 
  44.         
  45.         return $Summary 
  46.  
  47.  
  48.  
  49. $ServerName = "YourServerNameHere" 
  50. Get-MountPointInfo($ServerName) | convertto-html -title $ServerName > c:\Report-DriveSpace_for_$ServerName.html 

From

 

http://www.ericwoodford.com/query-size-and-free-space-windows-volume-mount-points

 

Regards,

Krishna

Concentrated Tech NSoftware Dell Compellent Sponsored by Idera and Concentrated Tech and NSoftware and Dell Compellent
Copyright 2011 PowerShell.com. All rights reserved.