Solved

Powershell script for Free Space on over 500 servers

Posted on 2014-09-08
1
365 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Synchronize a new Active Directory domain with an existing Office 365 tenant
Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…

910 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

21 Experts available now in Live!

Get 1:1 Help Now