PoshCode Archive  Artifact [2296abdfab]

Artifact 2296abdfabbbae67a0b7b3285e620c1934935a9c90e9e0737a4431e9d2dc6e8b:

  • File map-network-drive.ps1 — part of check-in [181f796cc4] at 2018-06-10 13:35:32 on branch trunk — Map network drive using powershell to call wscript.network. psdrive just does not act the same as a mapped network drive. I finally wrote these to connect to specific servers and directories to move files around. (user: 4wheels size: 1275)

# encoding: ascii
# api: powershell
# title: map network drive
# description: Map network drive using powershell to call wscript.network. psdrive just does not act the same as a mapped network drive. I finally wrote these to connect to specific servers and directories to move files around.
# version: 0.1
# type: script
# author: 4wheels
# license: CC0
# x-poshcode-id: 4054
# x-archived: 2015-05-07T23:43:49
# x-published: 2015-03-27T22:52:00
#
#
# map2_gps_prod.ps1
# Maps a network drive using PowerShell
# 
# 
# 
#

	$Drive = "O:"
	$UNC = "\\ampwcsqlsvr2\nam401k"
cls

# if the drive exists just remove it
	
	if (((New-Object -Com WScript.Network).EnumNetworkDrives() | Where-Object `
{$_ -eq $Drive})) 
	{ # true remove drive
	
	# Create the Com object with New-Object -com
	$net = $(New-Object -comobject WScript.Network)
	$net.RemoveNetworkDrive($Drive,1)
	
	
	} 
# if the drive does not exist just add it
if (!((New-Object -Com WScript.Network).EnumNetworkDrives() | Where-Object `
{$_ -eq $Drive}))
		{
		# Create the Com object with New-Object -com
		$net = $(New-Object -comobject WScript.Network)
		$net.mapnetworkdrive($Drive,$Unc) 
		}

# Launches windows Explorer and goes to the maped drive
explorer.exe $Drive