Solved

Powershell script for Free Space on over 500 servers

Posted on 2014-09-08
1
364 Views
Last Modified: 2014-09-08
Does anyone have a nice PS script that will retrieve the C:\ free space in MB.  I need it to run on over 500+ Server.  I would like it exported to a CSV if possible.  I appreciate the help and will reward 500 points as soon as I get a solution that works.

Thanks!
0
Comment
Question by:mystikal1000
1 Comment
 
LVL 40

Accepted Solution

by:
Subsun earned 500 total points
ID: 40309858
Following code should work for you.. input the server names in C:\Server.txt
GC C:\Server.txt | % {
$Comp = $_
Write-Host "Working on $Comp"
If (Test-Connection $Comp -Quiet -Count 2){
  Try{
	$disk = Get-WmiObject Win32_LogicalDisk -Filter "DeviceID='C:'" -ComputerName $Comp -ea STOP
		New-Object PSObject -Property @{
		Server = $Comp
		SizeMB = [math]::Round(($disk.Size /1MB),2)
		FreeSpaceMB = [math]::Round(($disk.FreeSpace /1MB),2)
		}
	}Catch{
		New-Object PSObject -Property @{
		Server = $Comp
		SizeMB = $_.Exception.Message
		FreeSpaceMB = $null
		}
	}
 }
 Else{
		New-Object PSObject -Property @{
		Server = $Comp
		SizeMB = "Down"
		FreeSpaceMB = $null
		}
 }
}| Select Server,SizeMB,FreeSpaceMB |
Export-Csv C:\report.csv -nti

Open in new window

Sample C:\Server.txt
ServerA
ServerB
ServerC

Open in new window

0

Featured Post

Why spend so long doing email signature updates?

Do you spend loads of your time carrying out email signature updates? Not very interesting are they? Don’t let signature updates get you down. Let Exclaimer Cloud - Signatures for Office 365 make managing email signatures a breeze.

Join & Write a Comment

Synchronize a new Active Directory domain with an existing Office 365 tenant
This article will help you understand what HashTables are and how to use them in PowerShell.
This tutorial will walk an individual through locating and launching the BEUtility application and how to execute it on the appropriate database. Log onto the server running the Backup Exec database. In a larger environment, this would generally be …
This tutorial will show how to configure a single USB drive with a separate folder for each day of the week. This will allow each of the backups to be kept separate preventing the previous day’s backup from being overwritten. The USB drive must be s…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now