Mapped networkdrive on logout

Posted by Robuust on Super User See other posts from Super User or by Robuust
Published on 2012-10-16T06:47:30Z Indexed on 2012/10/31 5:09 UTC
Read the original article Hit count: 412

I'm using a script to keep a mapped networkconnection alive, but ofcourse the mapped connection is gone when I logout. The point is now, that I'm running this on Windows Server 2008 R2, where I use remote desktop to login on the administrator account. However, it should remain logged in and not remove the mapped connection as this script takes care of not logging out on MS office 365 sharepoint.

Is there a way to keep the mapped networklocation (L:) available after logout? So the script can run to remain the connection?

# Create an IE Object and navigate to my SharePoint Site

$ie = New-Object -ComObject InternetExplorer.Application
$ie.navigate('https://xxx.sharepoint.com/')

# Don't need the object anymore, so let's close it to free up some memory
$ie.Quit()

# Just in case there was a problem with the web client service
# I am going to stop and start it, you could potentially remove this
# part if you want. I like it just because it takes out a step of 
# troubleshooting if I'm having problems.

Stop-Service WebClient
Start-Service WebClient

# We are going to set the $Drive variable here, this is just
# going to tell the command what drive letter to map you can 
# change this to whatever you want (if you change it to a 
# drive that is already mapped it will overwrite it, so be careful.

$Drive = "L:"

# You can change the drive destiniation to whatever you want,
# it has to be a document library or folder of course.
$DrvDest = "https://xxx.sharepoint.com/files/"

# Here is where we create the object to map the network drive and
# then map the network drive
$net = New-Object -ComObject WScript.Network;
$net.mapnetworkdrive($Drive,$DrvDest)

# That is the end of the script, now schedule this with task
# scheduler and every so often and you should be set.

© Super User or respective owner

Related posts about powershell

Related posts about windows-server-2008-r2