Mapping Network Drives on Windows the Right Way

Mapping a network drive turns a remote share into what looks like a local drive letter — convenient, but there are a few genuine gotchas worth knowing before relying on it heavily.

# Map a persistent network drive
New-PSDrive -Name "Z" -PSProvider FileSystem -Root "\\server\share" -Persist

# With explicit credentials for a different domain/user
$cred = Get-Credential
New-PSDrive -Name "Z" -PSProvider FileSystem -Root "\\server\share" -Credential $cred -Persist

# Remove a mapped drive
Remove-PSDrive -Name "Z"

The Classic Gotcha: Drives Don’t Reconnect for Scheduled Tasks

A mapped drive is tied to the interactive user session — a scheduled task running under a service account, or running when the user isn’t logged in, often can’t see the mapped drive at all. Use the full UNC path (\\server\share\file.txt) directly in scripts and scheduled tasks instead of relying on the drive letter, which sidesteps this entirely.