I saw the Get-NextFreeDrive
function in this answer and I wondered if there was a more efficient way to do this. It appears that the function in the linked answer keeps going through all the letters even if it has already found a free drive letter.
At PowerShell Magazine, we ran a brain teaser contest to find out the shortest answer to your question. Check this:
https://powershellmagazine.com/post/2012-01-12-find-an-unused-drive-letter/
There are several answers but here is my fav one:
ls function:[d-z]: -n | ?{ !(test-path $_) } | random