One last look at drives and then we are on to folders.
Script Center Home > Microsoft Windows 2000 Scripting Guide > Scripting Concepts and Technologies for System Administration > Script Runtime Primer > FileSystemObject > Managing Disk Drives Ensuring That a Drive is Ready
Listing 4.4 uses the Filesystem object to test if drives are ready. If you examine the script the majority of it, like a lot of VBScripts is taken up with display. Using PowerShell’s ability to substitute variables into a string we can cut that down and make a much simpler script.
#Listing 4.4
$fso = New-Object -ComObject "Scripting.FileSystemObject"
$fso.Drives | Foreach {
if ($_.IsReady){"DriveLetter $($_.DriveLetter) has $($_.FreeSpace) of freespace" }
else {"DriveLetter $($_.DriveLetter) is not ready" }
}
Get the filesystemobject as before. Pipe the drives into a foreach cmdlet and test on the IsReady parameter. If the drive is ready it displays the freespace otherwise it gives a message that the drive is not ready. It does pick up USB drives and memory sticks.
Share this post : | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |