The Collection

A collection of useful information.

PowerShell: Get First Open Drive Letter

Three lines of code to return the first in an array of available drive letters in the correct format for piping to New-PSDrive.

$letters = 65..90 | ForEach-Object{ [char]$_ + ":" }
$taken = Get-WmiObject Win32_LogicalDisk | select -expand DeviceID
$avail = ((Compare-Object -ReferenceObject $letters -DifferenceObject $taken)[1].InputObject).Replace(":","")