Access Network Location – PowerShell

In order to access a network location in PowerShell, we need to temporary map it to a drive locally, which we can then use as a reference for our further operation.

For ex, here, I want to copy a SharePoint package from a shared network location to my local machine.

If (!(Test-Path Z:))
 write-host "Attempting to map network drive, Z:" -foregroundcolor Magenta
 $map = new-object -ComObject WScript.Network
 $map.MapNetworkDrive("Z:", "\\lpdl-piyushk\sharedFolder", $true, "lpdl-piyushk\username", "Password")
 write-host "Z: mapping already exist" -foregroundcolor Green

# Copy the package from network location to local drive
write-host "copying wsp file" -ForegroundColor Magenta

Copy-Item Z:\SharePointWebPart.wsp P:\Piyush\SharePointWebPart.wsp -force

I have mapped the network location to Z: which is then used as a source location.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s