I am mapping my network drive using powershell like follows.
$net = new-object -ComObject WScript.Network
$net.MapNetworkDrive("r:", "$Folder","FALSE","Domain\UserName", "Password")
But here i am sending drive letter as r: . If r: drive is already utilized it would fail.
Is there any way to map drive to unassigned drive letter. ( For ex. If R: is already assigned but S: is not then it should map to S: drive automatically)
First you’ll need to get the next available drive letter. Here’s an example from Archive of PowerShell.com:
From PowerShell.com: