用 PowerShell 映射网络驱动器(New-PSDrive)
用 New-PSDrive -Persist 把 \\服务器\共享文件夹 映射成 Z: 盘,替代 net use,可保存凭据、重启后仍在。
运行 New-PSDrive -Name 'Z' -PSProvider FileSystem -Root '\\NAS\Media' -Credential (Get-Credential) -Persist。
01命令
命令
$ $cred = Get-Credential
New-PSDrive -Name 'Z' -PSProvider FileSystem -Root '\\NAS\Media' -Credential $cred -Persist02作用说明
New-PSDrive 的作用和 net use Z: \\NAS\Media 一样,把 UNC 路径映射成盘符,但它接收 PSCredential 凭据对象,可以写成脚本而不必明文存放密码。-Persist 参数决定映射是否出现在资源管理器里并在重启后保留——不加的话映射只存在于当前 PowerShell 会话。之后用 Remove-PSDrive 取消映射;传统的 net use Z: /delete 也仍然有效。
03风险
!注意: 不加 -Persist 资源管理器里看不到该盘;保存的凭据会存进 Windows 凭据管理器,不完全信任的共享请使用专门账户。
04撤销
撤销
$ Remove-PSDrive -Name Z -Force05来源
- New-PSDrive依据: New-PSDrive with -PSProvider FileSystem, -Root and -Persist maps a Windows drive letter to a network UNC path.
- New-PSDrive - SS64依据: Documents the -Persist switch that makes the mapped drive visible in File Explorer and across reboots.
最后验证: 2026-09-18 · 分类: 文件与文件夹
06相关方案
在 Windows 用 Test-NetConnection 测试 TCP 端口连通性
Windows 自带的 PowerShell 一行命令,直接回答“这个网络的 5432/3389/443 端口通不通”——不再需要安装 telnet 客户端。
用 Get-NetTCPConnection 列出监听端口和占用进程
netstat 的 PowerShell 原生替代品:按状态、端口、进程过滤连接,输出可直接管道处理而不用解析文本。
在 PowerShell 中用 Resolve-DnsName 查询 DNS 记录
nslookup 的现代化、可脚本化替代:查询指定记录类型、指定 DNS 服务器,并把结果当对象处理。