Map a Network Drive with PowerShell (New-PSDrive)
Map \\server\share to a drive letter with New-PSDrive -Persist, the PowerShell replacement for net use.
01Command
$ $cred = Get-Credential
New-PSDrive -Name 'Z' -PSProvider FileSystem -Root '\\NAS\Media' -Credential $cred -Persist02What it does
New-PSDrive maps a UNC path to a drive letter just like net use Z: \\NAS\Media, but takes a PSCredential object, which makes it scriptable without storing the password in plain text. The -Persist switch is what makes the drive appear in File Explorer and survive reboots — without it the mapping only exists inside the current PowerShell session. Remove-PSDrive unmaps it later; classic net use Z: /delete works too.
03Risk
04Undo
$ Remove-PSDrive -Name Z -Force05Sources
- New-PSDriveEvidence: New-PSDrive with -PSProvider FileSystem, -Root and -Persist maps a Windows drive letter to a network UNC path.
- New-PSDrive - SS64Evidence: Documents the -Persist switch that makes the mapped drive visible in File Explorer and across reboots.
Last verified: 2026-09-18 · Category: Files & Folders
06Related solutions
A built-in PowerShell one-liner that answers 'is port 5432/3389/443 actually open through this network?' — no telnet client needed.
The PowerShell-native replacement for netstat: filter connections by state, port, or process and pipe results instead of parsing text.
The modern, scriptable replacement for nslookup: ask for exact record types, hit specific DNS servers, and see TTLs as objects.