Advertisement
Guest User

Get-ADDiskUsage.ps1

a guest
Mar 25th, 2014
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <#
  2.     .Synopsis
  3.         Get the disk space details of remote computers read from Active Directory.
  4.        
  5.     .Description
  6.         This script helps you to get the disk space details of local disks and removable disks of
  7.         remote computers using powershell. It will also get the space details of mount points.
  8.  
  9.     .Parameter SearchBase
  10.         The Active Directory OU to search for computers to view disk details on.
  11.        
  12.     .Example
  13.         Get-DiskSpaceDetails.ps1 -SearchBase "OU=Faculty Tablets,OU=LSHS Computers,DC=lshs,DC=org"
  14.        
  15.         Get the total disk space, free disk space, and percentage disk free space details of computers in AD OU.
  16.        
  17.     .Example
  18.         Get-DiskSpaceDetails.ps1 -SearchBase "OU=Faculty Tablets,OU=LSHS Computers,DC=lshs,DC=org" | ? {$_."`%Freespace `(GB`)" -lt 5}
  19.        
  20.         Get all the drives which are having less than 5% free space.
  21.        
  22.     .Notes
  23.         NAME:      Get-ADDiskUsage.ps1
  24.         AUTHOR:     Austin Brashear
  25.         ORIGINAL AUTHOR:    Sitaram Pamarthi
  26.         WEBSITE:   http://techibee.com
  27.  
  28. #>
  29.  
  30. [cmdletbinding()]
  31. param(
  32.     [parameter(ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)]
  33.     [string]$SearchBase = "OU=Faculty Tablets,OU=LSHS Computers,DC=lshs,DC=org"
  34.    
  35. )
  36.  
  37. begin {
  38.    
  39. }
  40.  
  41. process {
  42.     $Computers = get-adcomputer -SearchBase $SearchBase -Filter "*" | Where {$_.Enabled -eq "true"}
  43.     foreach($Computer in $Computers) {
  44.         Write-Verbose "Working on $Computer"
  45.         if(Test-Connection -ComputerName $Computer.Name -Count 1 -ea 0) {
  46.             $VolumesInfo = Get-WmiObject -ComputerName $Computer.Name -Class Win32_Volume | ? {$_.DriveType -eq 2 -or $_.DriveType -eq 3 }
  47.             foreach($Volume in $VolumesInfo) {
  48.                
  49.                 $Capacity   = [System.Math]::Round(($Volume.Capacity/1GB),2)
  50.                 $FreeSpace  = [System.Math]::Round(($Volume.FreeSpace/1GB),2)
  51.                 $UsedSpace  = $Capacity - $FreeSpace
  52.                 $PctFreeSpace   = [System.Math]::Round(($Volume.FreeSpace/$Volume.Capacity)*100,2)
  53.                 $OutputObj  = New-Object -TypeName PSobject
  54.                 $OutputObj | Add-Member -MemberType NoteProperty -Name ComputerName -Value $Computer.Name
  55.                 $OutputObj | Add-Member -MemberType NoteProperty -Name DriveName -Value $Volume.Caption
  56.                 $OutputObj | Add-Member -MemberType NoteProperty -Name DriveType -Value $Volume.DriveType
  57.                 $OutputObj | Add-Member -MemberType NoteProperty -Name "Capacity `(GB`)" -Value $Capacity
  58.                 $OutputObj | Add-Member -MemberType NoteProperty -Name "Used Space `(GB`)" -Value $UsedSpace
  59.                 $OutputObj | Add-Member -MemberType NoteProperty -Name "FreeSpace `(GB`)" -Value $FreeSpace
  60.                 $OutputObj | Add-Member -MemberType NoteProperty -Name "`%FreeSpace `(GB`)" -Value $PctFreeSpace
  61.                 $OutputObj# | Select ComputerName, DriveName, DriveType, Capacity, FreeSpace, PctFreespace | ft -auto
  62.             }
  63.         } else {
  64.             Write-Verbose "$Computer is not reachable"
  65.         }
  66.     }
  67. }
  68.  
  69. end {
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement