Windows Mapped Drives Question


Recommended Posts

I am looking to create a script that will check the current drive maps on a computer and if the specific ones have been disconnected or lost then I want it to automatically reconnect it back. If possible.

 

For instance if I am suppose to have (H:) and (P:) connected I want it to check connection for those and if they aren't then I want it to reconnect it.

 

Thanks!

Link to comment
Share on other sites

NET USE H: \\SERVERNAME\SHARENAME /PERSISTENT:YES

NET USE P: \\SERVERNAME\SHARENAME /PERSISTENT:YES

 

the persistent keeps the drive mapped always.  If it falls off then the script will run the next time the logon.  Never had a drive delete or remove itself. 

 

If the computer are getting an x on the drive, change your power options on the computers.  the x will go away after the computer tries to reconnect to the drive or if you remove all power options on the nic card. 

Link to comment
Share on other sites

also are you using vbscript or a batch file?

 

batch file you can use

if exist n:\. goto mapn
goto :eof

:mapn
NET USE N: \\SERVERNAME\SHARENAME /PERSISTENT:YES

etc ect

Link to comment
Share on other sites

  • 3 weeks later...

I know your looking for a script, however,

 

Do you have domain privileges (Server 2008R2-2012) ?  If so, use a GPO to set drive letters to specific users or groups.

 

You can also prevent locals from changing drive letters in the future.

 

Let me know if you need help with this change

 

Michael

Link to comment
Share on other sites

I know your looking for a script, however,

 

Do you have domain privileges (Server 2008R2-2012) ?  If so, use a GPO to set drive letters to specific users or groups.

 

You can also prevent locals from changing drive letters in the future.

 

Let me know if you need help with this change

 

Michael

We can create a logon script to do just that.  No need for gpo.  GPOs can be finicky in regards to running.  If they don't get applied how do you force the mapping or manually map it?  Scripting it is a much better option because you have a backup when the gpo doesn't work for whatever reason, you can make the script part of the gpo if you so choose so that way you have the best of both worlds.  This is how I commonly execute drive mappings. 

 

Here are two scripting examples that will map a drive based on group membership (we can do pc name if they have a specific departmental prefix or suffix that would do it based on where the computer is, good for printer mappings by location).

 

kixtart script

 

map y: "\\servername\common share" /persistent:yes

 

if ingroup("domain group name")

map x: \\servername\sharename /persistent:yes

endif

 

vbscript:

 

set objSysInfo = CreateObject("ADSystemInfo")

Set objNetwork = CreateObject("Wscript.Network")

strUserPath = "LDAP://" & objSysInfo.UserName

Set objUser = GetObject(strUserPath)

For Each strGroup in objUser.MemberOf

strGroupPath = "LDAP://" & strGroup

Set objGroup = GetObject(strGroupPath)

strGroupName = objGroup.CN

Select Case strGroupName

Case "domain group name"

objNetwork.MapNetworkDrive "X:", "\\atl-fs-01\sharename"

End Select

 

Following either of these two examples will map the drive every time the user logs in, and if you change their membership will map the new drives for them as well.

Link to comment
Share on other sites

That reminds me I haven't glanced at our Domain logon scripts at work, our do something very similar, as well as other things 

Link to comment
Share on other sites

Consider using library's instead of mapped drives, it gives you a whole load more flexibility for example you can change the icon to something useful. pin them to the navtree or not, change the explorer columns to match the content  etc

 

if (!(Test-Path -path "$env:userprofile\AppData\Roaming\Microsoft\Windows\Libraries\Television.library-ms" )) {
SLUtil create Television
}
else {
}
if (!(Test-Path -path "$env:userprofile\AppData\Roaming\Microsoft\Windows\Libraries\Movies.library-ms" )) {
SLUtil create "Movies"
}
else {
}
if (!(Test-Path -path "$env:userprofile\AppData\Roaming\Microsoft\Windows\Libraries\New Movies.library-ms" )) {
SLUtil create "New Movies"
}
else {
}
if (!(Test-Path -path "$env:userprofile\AppData\Roaming\Microsoft\Windows\Libraries\Downloads.library-ms" )) {
SLUtil create Downloads
}
else {
}
if (!(Test-Path -path "$env:userprofile\AppData\Roaming\Microsoft\Windows\Libraries\Applications.library-ms" )) {
SLUtil create Applications
}
else {
}
SLUtil Icon "Downloads" "imageres.dll,-184"
SLUtil Icon "Movies" "imageres.dll,-1005"
SLUtil Icon "Applications" "imageres.dll,-87"
SLUtil Icon "Downloads" "imageres.dll,-184"
SLUtil Icon "New Movies" "imageres.dll,-1005"
SLUtil Icon "Television" "imageres.dll,-1008"
SLUtil addfolder Music "\\HyperV1\Music"
SLUtil addfolder Downloads "\\Getright\Downloads"
SLUtil addfolder Movies "\\HyperV1\Movies"
SLUtil addfolder Videos "\\HyperV1\Movies"
SLUtil addfolder "New Movies" "\\HyperV1\New Movies"
SLUtil addfolder Applications "\\HyperV1\Applications"
SLUtil addfolder Television "\\HyperV1\Television"

SLUtil NavPanePinnedState Videos False
SLUtil FolderType Music Music
SLUtil FolderType Downloads Generic
SLUtil FolderType Television Videos
SLUtil FolderType Movies Videos
SLUtil FolderType "New Movies" Videos

Link to comment
Share on other sites

This topic is now closed to further replies.