Connect_zlsh.ps1 976 B

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