Network drive mapping from PowerShell Script

Mapping Windows Network Drive using PowerShell

PowerShell scripts can be used to create network drives to Windows network shares on servers or NAS devices. Where batch processing is not the right choice, or where Group Policy is not possible, a PowerShell script can perform this task, for example, when running login scripts with remote clients via VPN, or clients that are not members of the AD domain.

PS-Script for Network Drive Mapping

This PowerShell Script example netdrive.ps1, creates the Windows network mapping to drive Z: for a specific user, whereby you can log on as a different user than you are authenticated with on the client.

The corresponding Windows network share is defined in line 7 at $sharePath, and the drive is assigned in line 8 at $mapDrive, adjusting the respective placeholder between the quotation marks. If further network shares are to be mapped, in the if loop copy lines 7 – 11 for the next network share using the variables $sharePath1 and $mapDrive1.

Windows PowerShell Credentials

Run PowerShell Script from Batch

If a batch is already in place, for example netlogon.bat, then execute netdrive.ps1 out from a batch file as follows:

After a successful logon, is it possible to check the network mapping, for this the processes are logged in the file netdrive.log.

Leave a Reply

Your email address will not be published. Required fields are marked *