| 12345678910111213141516171819202122232425262728 |
- # 测试网络连接
- if(!(Test-Connection 192.168.5.23 -Count 1 -Quiet)) {
- Write-Host "无法连接到服务器,请检查网络" -ForegroundColor Red
- Start-Sleep -Seconds 3
- exit
- }
- Write-Host "正在断开已有的 X 盘映射..."
- Net Use X: /delete /y 2>$null
- Write-Host "正在重新映射网络驱动器..."
- $result = Net Use X: "\\192.168.5.23\定制部" dzb /user:dzb /PERSISTENT:YES 2>&1
- if ($LASTEXITCODE -eq 0) {
- Write-Host "映射成功!" -ForegroundColor Green
- Write-Host "已将 \\192.168.5.23\定制部 映射到 X 盘" -ForegroundColor Green
- } else {
- Write-Host "映射失败,请检查网络连接或用户名密码是否正确" -ForegroundColor Red
- Write-Host $result -ForegroundColor Red
- Start-Sleep -Seconds 3
- }
- # 验证映射是否真的成功
- if(Test-Path X:) {
- Write-Host "验证成功: X 盘可以访问" -ForegroundColor Green
- } else {
- Write-Host "警告: X 盘似乎无法访问" -ForegroundColor Yellow
- }
|