header
header Register : : Login header
header
divider
menuleft
menuright
submenu
left

[August 25th, 2008] Check the home page regarding PowerShell related news from a brand new sponsor: Idera

mapping network drives and reusing the same letter
Last Post 05 Dec 2008 10:15 PM by glnsize. 3 Replies.
Printer Friendly
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
clay202User is Offline
New Member
New Member
Posts:7
Avatar

--
04 Dec 2008 10:57 PM  
hi all, this is probably not directly related to powershell but since I'm using powershell to perform this task -- I want to throw it out on the forum :)

here is the issue I'm having:

I've got a script that needs to map a network drive to server1 and server2.  When the script runs, it run on serverX and it will map a server1 network share onto servcerX.  The script will copy some files over to server1 and then perform a disconnect of the network drive and then begin on server2 with the same set of files. 

When the script attempts to map a network drive to server2 using the same drive letter, it gets into a funky state.  I perform a Test-Path on the drive letter to verify the drive is there and Powershell will report False.  I also cannot change directory to that drive.  But if I type in "net use" to view the mapped drives, I see Server1 in the list showing "OK" although I've perform the remove command before trying to map server2.  (It shows OK for server1 but I cannot change directory to it).  So i'm in this weird state.  Even if I perform a net use X: /delete, it removes but the drive but I cannot reuse the drive letter.  If I close the Powershell Window and reopen it -- then at that point, I can reuse the drive letter but I get stuck again if the script attempts to connect to server2.

I'm assuming this is a Microsoft thing (and it has nothing to do with powershell).  Does anyone know how I can re-use the same drive letter?  I can mess around with the script to use different drive letters but I prefer to use the same drive letter through out the process. 

The short story..tt seems it doesn't like me attempting to mount to server1, disconnect from server1, mount to server2 with the same dirve letter.

Down below is the syntax I'm using

$drvlet = "P:"
$fullunc = "\MyWebTest"
$net = New-Object -com WScript.Network
$net.mapnetworkdrive($drvlet,$fullunc)

I've tried using "net use" and WScript.Network and receive the same results.

thanks in advance for your answer(s)!

glnsizeUser is Offline
Basic Member
Basic Member
Posts:101

--
04 Dec 2008 11:46 PM  
Since your using powershell have you tried using the FileSystem provider and PSDrives...


New-PSDrive -Name Svr1 -PSProvider FileSystem -Root \\server1\Share 
Copy-Item Svr1:\somefile.txt $env:temp\somefile.txt 
Remove-PSDrive Svr1 

New-PSDrive -Name Svr2 -PSProvider FileSystem -Root \\server2\share
cd Svr2:
#you get the point... 


Unfortunately these "drives" exist only in your current session. Their is no persistence, but that doesn't sound like it would be a problem for you.
~Glenn
halr9000User is Offline
PowerShell MVP, Site Admin
Basic Member
Basic Member
Posts:334
Avatar

--
05 Dec 2008 02:42 PM  
You don't even need to map network drives at all if passthrough credentials work. Just use the UNC path--in other words, something you wish you could have done from DOS since the 90's, you can now do in powershell.
Community Director, PowerShellCommunity.org
Co-host, PowerScripting Podcast
Author, TechProsaic
glnsizeUser is Offline
Basic Member
Basic Member
Posts:101

--
05 Dec 2008 10:15 PM  
Hal that's a good point looking at the wscript.network I should have spotted a fellow vbscript convert. Powershell is a cmdline first copy \\server\share\somefile.txt $env:temp works just fine... No need to spin up a file system object or initialize a dll. Perhaps I should have asked why you need to map a drive? By the way when i use chrome with the new forum software all my line breaks go away.
You are not authorized to post a reply.

Active Forums 4.1
right
   
footer Sponsored by Quest Software • SAPIEN Technologies • ShellTools, LLC • Microsoft Windows Server 2008 footer
footer