Solved

Powershell script for Free Space on over 500 servers

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

A brief introduction to what I consider to be the best editor for PowerShell.
Windows 10 came with  a lot of built in applications, Some organisations leave them there, some will control them using GPO's. This Article is useful for those who do not want to have any applications in their image (example:me).
This tutorial will give a short introduction and overview of Backup Exec 2012 and how to navigate and perform basic functions. Click on the Backup Exec button in the upper left corner. From here, are global settings for the application such as conne…
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

734 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