Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Map drives and change their name.

 
Logged in as: Guest
arrSession:exec spGetSession 2,5,60694
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> Windows PowerShell >> Map drives and change their name.
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Map drives and change their name. - 5/25/2008 11:29:29 PM   
  chrspe

 

Posts: 3
Score: 0
Joined: 5/25/2008
Status: offline
Hi.
I'm totaly new to this with scripting and I have some questions.
I would like to have a script that map drives trough user login in AD and map certain drives based on
witch group the user is a member in (i.e users in group production get X: mapped to \\server1\prod)
And the mapped drive should change name to what I give it (i.e from "prod on server1 (X:)" to just Prod (X:)).

I would like to map the home directory to the specific user,
i.e H: to \\server1\users\xxxxxx, to Home (H:). (xxxxxx being the user login and homedirectory)
I now have AD to map home directory on every user, should I clear the field that maps this drive and type it in the script? If not, how can i rename it?

I've come across several vbs-script that does this but i can't get them to work together in just one script.
These are the two scripts that I've been looking at:
First the user-based:
--------------------
On Error Resume Next

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 "Sales"
           objNetwork.MapNetworkDrive "Z:", "\\server1\Sales"
           
   Case "Prod"
       objNetwork.MapNetworkDrive "G:", "\\server1\Prod"
          
   End Select
Next
----------------------
Then for name change:
----------------------
Option Explicit
Dim objNetwork, strRemotePath1, strRemotePath2, strRemotePath3, strRemotePath4
Dim strDriveLetter1, strDriveLetter2, strDriveLetter3, strDriveLetter4
Dim strNewName1,  strNewName2, strNewName3, strNewName4
Dim objShell

strDriveLetter1 = "K:"
strDriveLetter2 = "S:"
strDriveLetter3 = "T:"
strDriveLetter4 = "X:"
strRemotePath1 = "\\server1\ftproot"
strRemotePath2 = "\\server2\Mail"
strRemotePath3 = "\\server1\All"
strRemotePath4 = "\\server1\Pic"
strNewName1 = "FTP"
strNewName2 = "Mail"
strNewName3 = "All"
strNewName4 = "Pictures"


Set objNetwork = CreateObject("WScript.Network")

' Section which maps 4 drives, K:, S:, T:, X:
objNetwork.MapNetworkDrive strDriveLetter1, strRemotePath1
objNetwork.MapNetworkDrive strDriveLetter2, strRemotePath2
objNetwork.MapNetworkDrive strDriveLetter3, strRemotePath3
objNetwork.MapNetworkDrive strDriveLetter4, strRemotePath4

Set objShell = CreateObject("Shell.Application")
objShell.NameSpace(strDriveLetter1).Self.Name = strNewName1
objShell.NameSpace(strDriveLetter2).Self.Name = strNewName2
objShell.NameSpace(strDriveLetter3).Self.Name = strNewName3
objShell.NameSpace(strDriveLetter4).Self.Name = strNewName4

' Extra code just to add a message box
'WScript.Echo "Map drives " & strDriveLetter1 & " & " & strDriveLetter2

Wscript.Quit
-------------------

Is it possible to combine them into one? And how to change the name on the home directory?
Thanks.
 
 
Post #: 1
 
 RE: Map drives and change their name. - 6/1/2008 2:23:34 PM   
  SAPIENScripter


Posts: 275
Score: 2
Joined: 11/1/2006
From: SAPIEN Technologies
Status: offline
This is not really a PowerShell question.  If you haven't already post this in the VBScript forum.

_____________________________

Jeffery Hicks
Windows PowerShell MVP
SAPIEN Technologies - Scripting, Simplified. www.SAPIEN.com

Follow Me: http://www.twitter.com/JeffHicks

(in reply to chrspe)
 
 
Post #: 2
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> Windows PowerShell >> Map drives and change their name. Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts