Solved

Powershell script for Free Space on over 500 servers

Posted on 2014-09-08
1
370 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

What, When and Where - Security Threats from Q1

Join Corey Nachreiner, CTO, and Marc Laliberte, Information Security Threat Analyst, on July 26th as they explore their key findings from the first quarter of 2017.

Question has a verified solution.

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

The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
For anyone that has accidentally used newSID with Server 2008 R2 (like I did) and hasn't been able to get the server running again because you were unlucky (as I was) and had no backups - I was able to get things working by doing a Registry Hive rec…
This tutorial will walk an individual through the process of installing the necessary services and then configuring a Windows Server 2012 system as an iSCSI target. To install the necessary roles, go to Server Manager, and select Add Roles and Featu…
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…

615 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