02 Apr

Azure Drives: Checking storage capacity

Imagine that you have an entire server park, and that you need to know your storage capacity on ALL servers.
Instead of checking your servers individually, you can have a simple PowerShell script do the work for you, and display all information in a .txt-file. The reason why I run this, is because it helps with monitoring and keeps you up-to-date (given that you run this on a decent basis). It also helps me with planning next steps for server improvements, especially when you need to install new software.

Prerequisites:

  • A domain controller
  • An account with FULL administrator rights

The admin account will enable you to run the command in 1 go, without authenticating to each server you have. This just makes the job easier.



#Your Servers
$AllServers = ("List of your servers, by name")
#Your Domain
$domain = "your domain"


#Returns Value in GB
function getInGb($drive_kb){
    return $drive_kb / 1024 /1024 /1024
}

#Retrieves drive size and free space
function get_drives(){
    foreach($server in $AllServers){
        $dcServer = $server +"."+$domain
        "`r`n" + $dcServer +"`r`n"
        $drives = Get-WmiObject Win32_LogicalDisk -ComputerName $dcServer
        
        foreach($drive in $drives){
            $sizeFree = getInGb($drive.freespace)
            $size = getInGb($drive.size)
            #DriveType 5 is CD-ROM and 2 is FlopyDisk
            if($drive.DriveType -ne 5){
                if($drive.DriveType -ne 2){
                    $drive.DeviceID+ " total: " +"{0:N2}" -f $size + " GB free space: " + "{0:N2}" -f $sizeFree + " GB"
                }
            }
            
        }
  
    }

}

#Call functions
get_drives > Location to store the .txt with the results

As you can see, this involves a bit more typing than the previous script I posted.

The server names in the $AllServers must be EXACTLY the same as defined in the DNS. Otherwise the command will fail (I had this problem the first time, so watch out).

And that is also the only hick-up that you can have. The rest of the command speaks for itself.
The result of the text file will be something like this:

server1.domain.lan C: total: 99,90 GB free space: 64,81 GB
server2.domain.lan C: total: 105,00 GB free space: 71,97 GB
server3.domain.lan C: total: 99,90 GB free space: 45,10 GB




Leave a Reply

Your email address will not be published. Required fields are marked *