PowerShell script to get disk space (Get-FreeDiskSpace) is an Advanced PowerShell function for reporting free disk spaces.
It may report on a single server if the -Servername parameter is specified;
It may report on servers from a text file if the -Serverfile parameter is specified.
Report for a single server is displayed on the console;
report for servers from a text file is stored on a CSV file located in \CSVReports folder.
Get-FreeDiskSpace function comes with error logging. Any server that is offline
or with wrong name will be logged in the \logs folder. All other errors are displayed on the console.
This is a Function. If you wish to download the original script for the function, click here the link below:
Get-FreeDiskSpace has the following functionalities:
#1. Reports on one server when you specify the -Servername parameter. Displays report on the console.
#2. Reports on multiples servers when you specify the -Serverfile parameter. Report exported to a CSV file.
#3. By default, Get-FreeDiskSpace reports only disks on the server (s) with % free space less than or equal to 10%.
#4. Provides option to specify a % free space you wish to report (using the -PerCentageFree parameter).
#5. Supports error logging and display.
#6. Supports default parameters. For example to report 10% free disk space on a server named 70411SRV1, run the command:
Get-FreeDiskSpace 70411SRV1 -RunAsCred 70511Lab\Administrator
To download the function including full installation and usage instructions, click Dolwnoad Get-FreeDiskSpace
Installation and examples
Follow the steps below to install and use the Get-FreeDiskSpace PowerShell function:
#1. Download and unzip Get-FreeDiskSpace.zip.
#2. Copy Get-FreeDiskSpace folder to the following locations: \Documents\WindowsPowerShell\Modules and/or \Program Files\WindowsPowerShell\Modules
#3. Run the command:
#4. To get help and information about the Get-FreeDiskSpace function, run the command:
To get detailed help, run:
Get-Help Get-FreeDiskSpace -Detailed
To get Full help, run
Get-Help Get-FreeDiskSpace -Full
#5. To run disk report for a single server with the default PerCentageFree parameter (10%), enter the following commands:
Get-FreeDiskSpace -ServerName 70411SRV1 -RunAsCred 70411Lab\administrator
You will be prompted to authenticate the account you entered above:
NOTE: This account MUST have administrator privileges on all servers you wish to run disk report on
#6. To run disk report for a single server with a higher PerCentageFree (reports free space for all drives less than or equal to 30% free space) parameter, enter the following commands:
Get-FreeDiskSpace -ServerName 70411SRV1-RunAsCred 70411Lab\administrator -PerCentageFree 30
Confirm your password: Notice that more drives are now returned for the same server:
#7. To run a report from a text file as input and return free space on all drives, enter the commands below:
Get-FreeDiskSpace -Serverfile ‘E:\Imput\Servers.txt’ -RunAsCred 70411lab\administrator -PerCentageFree 100
Confirm your account: Report will take a while and return as shown below:
As indicated in the console, a CSV report has been created in the location:
Report has same headers as the console report for a single
#1. If you enter a folder path instead of a text file path, the following errors will be returned:
#2. When you run report from a text file, all servers that could not be reached are logged in the \logs folder. Mine was logged in the following location:
Thank you for using Get-FreeDiskSpace by iTechguides.com.
Download more PowerShell functions and iTechguides.com/blog