Tuesday, 12 April 2016

PowerShell Script: Find out free disk space from multiple servers

Hi All, this is my very first post on PowerShell Script. Today, I am going to share a script that you can use to find out free disk space from multiple servers. You will have to create a Text file and a PowerShell script to accomplish this.

Let’s begin by creating a Text file. I have setup a folder on my C: Drive called PS_Script (C:\ PS_Script). I created a Text file, ServerNames.txt, and saved it in C:\PS_Script folder.



Use following code to create a PowerShell script and save it as DiskReport.PS1.

#Get Current date
$currdate = (Get-Date).tostring("dd-MM-yyyy")

#Set path for output file
$report = "C:\PS_Script\" + "DiskSpaceReport_" + "$Currdate.html"

#Run command to get free disk space from multiple servers and export output to HTML file
Get-WmiObject Win32_LogicalDisk -filter "DriveType=3" -computer (Get-Content C:\PS_Script\ServerNames.txt) | Select SystemName,DeviceID,VolumeName,@{Name="Size(GB)";Expression={"{0:N1}" -f($_.size/1gb)}},@{Name="FreeSpace(GB)";Expression={"{0:N1}" -f($_.freespace/1gb)}} | ConvertTo-HTMl | Out-File $report

When you run above PowerShell script, it will create a HTML file in C:\PS_Script folder.  Please make sure that you are running the PowerShell script using your admin account.

I hope you like this script.

Disclaimer: www.TechieTalks.co.uk does not conceal the possibility of error and shortcomings due to human or technical factors. www.TechieTalks.co.uk does not bear responsibility upon any loss or damage arising from conduct or activities related to the use of data and information contained in this blog.

No comments:

Post a Comment