Skip to main content
Hands-on lab

Write and run a PowerShell script to map a network drive

Automate a repeated network-drive setup by writing a one-line PowerShell script with New-PSDrive, running the script, and confirming the persistent S: drive points to the expected UNC share. This page teaches a job procedure. These are not exam questions, this is not a score predictor, and nothing here is taken from any certification exam.

Steps

  1. 1

    Use Set-Content to create mapdrive.ps1 with a New-PSDrive command that maps S: to \\fileserver\shared with -Persist and -Scope Global.

  2. 2

    Run .\mapdrive.ps1 from the current PowerShell folder.

  3. 3

    Run Get-PSDrive -Name S and confirm the persistent FileSystem drive appears as S: with S:\ as its root.

What you should see

The script output shows an S drive with the FileSystem provider and the root \\fileserver\shared. Get-PSDrive then shows the persistent drive as S: with S:\ as its root.

Study the concept