Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <#
- .Synopsis
- Get the disk space details of remote computers read from Active Directory.
- .Description
- This script helps you to get the disk space details of local disks and removable disks of
- remote computers using powershell. It will also get the space details of mount points.
- .Parameter SearchBase
- The Active Directory OU to search for computers to view disk details on.
- .Example
- Get-DiskSpaceDetails.ps1 -SearchBase "OU=Faculty Tablets,OU=LSHS Computers,DC=lshs,DC=org"
- Get the total disk space, free disk space, and percentage disk free space details of computers in AD OU.
- .Example
- Get-DiskSpaceDetails.ps1 -SearchBase "OU=Faculty Tablets,OU=LSHS Computers,DC=lshs,DC=org" | ? {$_."`%Freespace `(GB`)" -lt 5}
- Get all the drives which are having less than 5% free space.
- .Notes
- NAME: Get-ADDiskUsage.ps1
- AUTHOR: Austin Brashear
- ORIGINAL AUTHOR: Sitaram Pamarthi
- WEBSITE: http://techibee.com
- #>
- [cmdletbinding()]
- param(
- [parameter(ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)]
- [string]$SearchBase = "OU=Faculty Tablets,OU=LSHS Computers,DC=lshs,DC=org"
- )
- begin {
- }
- process {
- $Computers = get-adcomputer -SearchBase $SearchBase -Filter "*" | Where {$_.Enabled -eq "true"}
- foreach($Computer in $Computers) {
- Write-Verbose "Working on $Computer"
- if(Test-Connection -ComputerName $Computer.Name -Count 1 -ea 0) {
- $VolumesInfo = Get-WmiObject -ComputerName $Computer.Name -Class Win32_Volume | ? {$_.DriveType -eq 2 -or $_.DriveType -eq 3 }
- foreach($Volume in $VolumesInfo) {
- $Capacity = [System.Math]::Round(($Volume.Capacity/1GB),2)
- $FreeSpace = [System.Math]::Round(($Volume.FreeSpace/1GB),2)
- $UsedSpace = $Capacity - $FreeSpace
- $PctFreeSpace = [System.Math]::Round(($Volume.FreeSpace/$Volume.Capacity)*100,2)
- $OutputObj = New-Object -TypeName PSobject
- $OutputObj | Add-Member -MemberType NoteProperty -Name ComputerName -Value $Computer.Name
- $OutputObj | Add-Member -MemberType NoteProperty -Name DriveName -Value $Volume.Caption
- $OutputObj | Add-Member -MemberType NoteProperty -Name DriveType -Value $Volume.DriveType
- $OutputObj | Add-Member -MemberType NoteProperty -Name "Capacity `(GB`)" -Value $Capacity
- $OutputObj | Add-Member -MemberType NoteProperty -Name "Used Space `(GB`)" -Value $UsedSpace
- $OutputObj | Add-Member -MemberType NoteProperty -Name "FreeSpace `(GB`)" -Value $FreeSpace
- $OutputObj | Add-Member -MemberType NoteProperty -Name "`%FreeSpace `(GB`)" -Value $PctFreeSpace
- $OutputObj# | Select ComputerName, DriveName, DriveType, Capacity, FreeSpace, PctFreespace | ft -auto
- }
- } else {
- Write-Verbose "$Computer is not reachable"
- }
- }
- }
- end {
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement