Language: PowerShell
PS Check Remote Machine Disk space & Threashold Per Disk/Volume
1: # 2: # check disk space 3: # Author : Barry 'Ackros' Reilly 4: # Date: August 2009 5: # Revision : A03 6: # SystemName,Label,Name,DriveLetter,DriveType,Capacity,Freespace 7: # 8: 9: param ( 10: [string] $Hostname 11: ) 12: 13: # Return syntax if no parameters given 14: if (!param) 15: { 16: Write-Host "Syntax: script.ps1 <hostname> e.g. script.ps1 host or script.ps1 host.fqdn.local" 17: BREAK 18: } 19: 20: # if(!$cred) {Get-Credential} 21: 22: $DiskSpaceResults=Get-WmiObject Win32_Volume -Credential $cred -ComputerName $Hostname | Select-Object SystemName,Label,Name,DriveLetter,DriveType,Capacity,Freespace 23: 24: foreach ( $DiskSpaceResult in $DiskSpaceResults) 25: { 26: Write-Host "Host Name: " $Hostname 27: 28: # convert bytes to MB or GB 29: $CapacityMB=($DiskSpaceResult.Capacity / 1MB) 30: $FreeMB=($DiskSpaceResult.FreeSpace / 1MB) 31: 32: #convert MB to GB 33: 34: $CapacityGB=($CapacityMB/1GB) 35: $FreeGB=($FreeMB/1GB) 36: 37: # if no label on disk 38: 39: if (!$DiskSpaceResult.Label) 40: {Write-Host "Disk Label: NONE SET" } 41: else 42: {Write-Host "Disk Label: " $DiskSpaceResult.Label} 43: Write-Host " " 44: Write-Host "Disk Capacity (MB): " $CapacityMB 45: Write-host "Disk Space Free (MB:" $FreeMB 46: 47: 48: # calc Space used in MB 49: $SpaceUsedMB=([double]$CapacityMB - [double]$FreeMB) 50: Write-Host "Disk Space Used (MB):" $SpaceUsedMB 51: 52: # calc and return as a percentage 53: 54: 55: # calc Free Space as a Percentage 56: 57: $HostFreeSpacePercent =( ([double]$DiskSpaceResult.FreeSpace/[double]$DiskSpaceResult.Capacity) * 100) 58: Write-Host "Disk Space Free % (MB):" $HostFreeSpacePercent 59: # (SpaceUsed / Space Capacity ) * 100 == % used 60: 61: $HostDiskUsedPercent=(([double]$HostDiskSpaceUsedMB/[double]$HostDiskSpaceCapacityMB)*100) 62: 63: Write-Host "Disk Space Used % (MB):" $HostDiskUsedPercent 64: 65: # Set the Threashold Value to look for 66: 67: # debug trap 101 68: $gotonextrecord = Read-Host "Debugging - Continue (y/n) ?" 69: 70: if ($gotonextrecord = 'n') {break} 71: 72: } 73: 74: 75: 76:
Tags:
Description:
work in progress to accept $hostname as param and then gwmi the host for its logical disk setup, capacity, free space, used, convert to MB & GB, get % used and then check if % used is 90%
Report Abuse
Subscribe
Discuss
What's new
What is it
New Snippet
Recent Snippets
My Snippets
Web Code
Search

