PowerShell pack: Get-FreeDiskSpace
The Filesystem module has some interesting things for us. The get-freediskspace function looked useful – so I tried it. It is safe so you can try this at home
PS> Get-FreeDiskSpace
Timestamp CounterSamples
--------- --------------
25/02/2010 22:13:44 \\rslaptop01\logicaldisk(harddiskvolume1)\% free space :
71.7171717171717
\\rslaptop01\logicaldisk(c:)\% free space :
64.7910448672172
\\rslaptop01\logicaldisk(d:)\% free space :
85.3700423978962
\\rslaptop01\logicaldisk(g:)\% free space :
60.9804902451226
\\rslaptop01\logicaldisk(_total)\% free space :
71.1405628168288
\\rslaptop01\logicaldisk(harddiskvolume1)\free megabytes :
71
\\rslaptop01\logicaldisk(c:)\free megabytes :
106153
\\rslaptop01\logicaldisk(d:)\free megabytes :
63628
\\rslaptop01\logicaldisk(g:)\free megabytes :
1219
\\rslaptop01\logicaldisk(_total)\free megabytes :
171071
I’ve seen, and written, a few utilities to get free disk space. This one is different because it uses performance counters. It shows the free space as a % and in megabytes. As an example of how to use counters its worth examining the code using:
(get-command Get-FreeDiskSpace).Definition
I wanted to compare this to the information given by get-psdrive which displays the used and free space for drives. I was surprised to see a whole list of drives I wasn’t expecting including:
MyComputer
MyMusic
MyPictures
Personal
Program...
Programs
Recent
SendTo
StartMenu
Startup
System
Templates
Variable
A quick look at the module code shows that it runs the Mount-SpecialFolder function after loading the module. Umm – that is a bit naughty I think – I don’t like configuration changes like this sneaking in. Next time we’ll have a look at the mount-specialfolder function.