07 March,2019 by Tom Collins
Question: I'm currently building a script to return all SQL Servers in the environment . As part of the recordset I need to return the aggregated free space for the drives on the server. So for example , if these were the drive free space details for a specific servers
C:\ 52 GB free
E:\ 7 GB free
F:\ 9 GB free
G:\ 5 GB free
than the figure to return is 73 GB ,
I'd like this to be a Powershell function , so then I can reference it for any server, therefore the input parameter should be servername
Answer:Find a some Powershell code which should cover your requirements.
Function GetAggDiskFree([string]$server) { $computer = $server $disks = @(Get-WmiObject Win32_LogicalDisk -ComputerName $computer -Filter 'DriveType = 3') $TotalDiskFree = 0 $disks | ForEach { $TotalDiskFree += $_.FreeSpace } return $TotalDiskFree } ##example of how to execute ##GetAggDiskFree MY_SERVER1
x
If you're looking to report the Aggregated Disk Space on a server use the function on : Powershell script – Function to return server disk capacity
Read more ways of using Powershell to return disk space
Powershell script to check disk space on remote servers (SQL ...
Free disk space on drives using Powershell (SQL Server DBA)
This is only a preview. Your comment has not yet been posted.
As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.
Having trouble reading this image? View an alternate.
Posted by: |