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
Solved

Powershell script for Free Space on over 500 servers

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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

"Migrate" an SMTP relay receive connector to a new server using info from an old server.
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 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 steps necessary to install and configure the Windows Server Backup Utility. Directly connect an external storage device such as a USB drive, or CD\DVD burner: If the device is a USB drive, ensure i…

856 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