Jump to content

8 posts in this topic

Posted

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!

Share this post


Link to post
Share on other sites

Posted

Do you want this to run at boot? Login? Periodically; say every 10mins?

Share this post


Link to post
Share on other sites

Posted

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. 

Share this post


Link to post
Share on other sites

Posted

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

Share this post


Link to post
Share on other sites

Posted

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

Share this post


Link to post
Share on other sites

Posted

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.

Share this post


Link to post
Share on other sites

Posted

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

Share this post


Link to post
Share on other sites

Posted

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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.