For some reason there are times windows fail to reconnect mapped drives, a simple way to bypass this is by creating a set of startup scripts during logon.
First of all create a mapdrives.cmd file with the following commands inside it.
The file should be run at a regular but not at an elevated command prompt because it should be run at the same privilege as Windows Explorer
PowerShell -Command "Set-ExecutionPolicy -Scope CurrentUser Unrestricted" >> "%TEMP%\StartupLog.txt" 2>&1
PowerShell -File "%SystemDrive%\Scripts\MapDrives.ps1" >> "%TEMP%\StartupLog.txt" 2>&1
Then create a poweshell scipt mapdrives.ps1 file with the following commands inside it.
$i=3
while($True){
$error.clear()
$MappedDrives = Get-SmbMapping |where -property Status -Value Unavailable -EQ | select LocalPath,RemotePath
foreach( $MappedDrive in $MappedDrives)
{
try {
New-SmbMapping -LocalPath $MappedDrive.LocalPath -RemotePath $MappedDrive.RemotePath -Persistent $True
} catch {
Write-Host "There was an error mapping $MappedDrive.RemotePath to $MappedDrive.LocalPath"
}
}
$i = $i - 1
if($error.Count -eq 0 -Or $i -eq 0) {break}
Start-Sleep -Seconds 30
}
Now we are ready to run these two commands during logon.
Note This workaround works only for the device that has network access at logon. If the device has not established a network connection by the time of logon, the startup script won’t automatically reconnect network drives.
- Copy the script file (Mapdrives.cmd) to the following location:
%ProgramData%\Microsoft\Windows\Start Menu\Programs\StartUp
- Copy the script file (Mapdrives.ps1) to the following location:
%SystemDrive%\Scripts\
- A log file (StartupLog.txt) will be created in the %TEMP%\ folder.
- Log off, and then log back on to the device to open the mapped drives.