Showing posts with label disk. Show all posts
Showing posts with label disk. Show all posts

Wednesday, 28 September 2016

Querying/Checking Windows Logical Disks using Powershell

Below is a script you can use to check/query windows logical disks using powershell. This can be useful to regularly check the free space on logical drives on a windows server or PC.

$diskreport = Get-WmiObject Win32_logicaldisk | Select DeviceID, MediaType, VolumeName, `
    @{Name="Size(GB)";Expression={[decimal]("{0:N0}" -f($_.size/1gb))}}, `
    @{Name="Free Space(GB)";Expression={[decimal]("{0:N0}" -f($_.freespace/1gb))}}, `
    @{Name="Free (%)";Expression={"{0,6:P0}" -f(($_.freespace/1gb) / ($_.size/1gb))}}

The script uses the get-wmiobject cmdlet to query the logical disks configured within windows. The results are then compiled into the $diskreport variable so they can then be further queried or exported to a .csv file.

Free space as a percentage is also calculated automatically as part of this script.

A sample output from the $diskreport variable is below (A:\ and D:\ are the floppy drive and DVD drive with no media loaded which is why they've returned values of 0)

Monday, 12 September 2016

Windows Server - Unable to extend volume - There is not enough space available on the disk(s) to complete this operation

Came across this issue today on a virtual machine running in a VMware environment. After allocating additional hard disk space to the virtual machine (running Windows Server 2012), the following error appeared when attempting to extend the hard disk;



"There is not enough disk space available on the disk(s) to complete this operation"

Even though the space was showing as "unallocated" in disk management, this error still appeared when trying to extend the volume.

The fix - turns out it was quite simple. From within the Disk Management utility, go to Action > Rescan Disks then try running the extend disk again.