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.

WindowsnetworkFilesnetwork-drivepowershellLow risk
Run New-PSDrive -Name 'Z' -PSProvider FileSystem -Root '\\NAS\Media' -Credential (Get-Credential) -Persist.

01Command

Command
$ $cred = Get-Credential
New-PSDrive -Name 'Z' -PSProvider FileSystem -Root '\\NAS\Media' -Credential $cred -Persist

02What 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

RiskLow risk
RequirementsThe share must be reachable on the network; use an admin PowerShell only if mapping for other accounts.
!Warning: Without -Persist the drive won't show in File Explorer; with credentials saved, Windows stores them in Credential Manager — use a dedicated account for shares you don't fully trust.

04Undo

Undo
$ Remove-PSDrive -Name Z -Force

05Sources

  • New-PSDrive
    Microsoft Learn · vendor-doc · 2026-09-17
    Evidence: New-PSDrive with -PSProvider FileSystem, -Root and -Persist maps a Windows drive letter to a network UNC path.
  • New-PSDrive - SS64
    SS64 · technical · 2026-09-17
    Evidence: 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