内网使用 Win10 挂载 Nas 的小伙伴偶尔会遇到一个问题,开机之后,打开此电脑看到网络位置的挂载磁盘都是红叉或者个别有红叉,但是实际双击红叉的磁盘还是能打开使用,也就是说他显示 nas 映射网络驱动器断开了但却能连上。
造成这个原因基本是因为系统加载速度早于网络设备加载速度,今天分享一下如何解决这个问题。
一、新增文件 MapDrives.ps1,保存在目录 C:\Scripts
$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 "Shared folder connection error: $MappedDrive.RemotePath to drive $MappedDrive.LocalPath"
}
}
$i = $i - 1
if($error.Count -eq 0 -Or $i -eq 0) {break}
Start-Sleep -Seconds 30
}