Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

script for mapping shares across forests 1

Status
Not open for further replies.

astaylor

MIS
Mar 14, 2007
138
US
My company is in the process of setting up a new domain for reasons that would take to long to explain. What i am trying to do is map a users share from the old domain when they login to the new domain. The problem is...usernames are different. I do have a trust setup and i can map the share manually successfully. So there shouldnt be an issue accessing anything.

Heres what i am looking to do, if it is possible.

is there a way to get the "displayName" object from the new domain and use it find a matching "displayName" in the old domain. If the query locates a match then return the username of the old domain account and map a drive in the new domain based on the username with a $ for the share.

something like this:

(i dont know much syntax so its mixed with code and english)

On Error Resume Next
Set objNetwork = WScript.CreateObject("WScript.Network")

User = objNetwork.displayName
Query olddomain to find a displayName match with User
If there is a match
return username from old domain
objNetwork.MapNetworkDrive "X:", "\\server\" & username & "$", True
If Not
End Script
End If

Something like that would be awesome, i hope it can be done.

Thanks,


-drew
 
Sounds like the setup of this was not done in a manner conducive to what you need. I would suggest that you wipe out the user accounts on the new system and then use ADMT to create the accounts and preserve SID history. Later when your migration is completed you could use vbscript to rename the accounts and the associated folders.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
There is a reason for the way it is setup and to go into it in depth would waste yours and my time. Let's just say it has to be that way for now with different usernames.

Can what i need to happen be done or am i out of luck? Desktop Authority can do it, but i would like to avoid purchasing it if theres a work around.

-drew
 
Create an array of all user names with old and new names and use that information to do your mappings.

Creating the array will be tedious depending on how many users you have, but once complete the rest is a breeze.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Mark,

could you give me an example of creating the array with 1 user and then i can run with it from there. I am a scripting noob.

Thanks,


-drew
 
Code:
Set WSHNetwork = CreateObject("Wscript.Network")
UserString = LCase(WSHNetwork.Username)

Dim Users(1,1)
Users(0,0) = "oldName"
Users(0,1) = "newName"
Users(1,0) = "NextOldName"
Users(1,1) = "NextNewName"

For x = 0 To 1

  If LCase(Users(x,0)) = UserString Then
        WSHNetwork.MapNetworkDrive "X:", "\\server\" & Users(x,1)& "$", True
  End If
Next

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
That works very well Mark. Thanks.

Just would hate to type out close to 500 user account names plus the old names. Does anyone have any ideas on how to query AD with im guessing ldap through vbscript and store the username that matches a new users displayName into a variable that can be used to map the drive. The displayNames match from domain to domain, that users names havent changed. Just their account names.

It would be nice to grab the current displayName of the new user, which i guess would look like this:

Set objNetwork = WScript.CreateObject("WScript.Network")
User = objNetwork.displayName

then query the old domain for a matching displayName. If a match is found then pull that username of the old account that matched and put it into a variable.

This is what i don't know how to do. query the old domain.

After that is done then it would be easy to just map the drive based on the old username with this:

WSHNetwork.MapNetworkDrive "X:", "\\server\" & oldusername & "$", True


if this is possible then it would save alot of headache of typing accounts manually and adding and subtracting as employees come and go.

Thanks,


-drew
 
Wscript.Network does not have a displayName property.

You could use that to grab UserName, ComputerName, DomainName, organization, site or UserProfile.

A suggestion for you is to perhaps send out a spreadsheet to departments and ask each department to provide this information for you in Excel. You could then manipulate it to make your array code.

Another idea would be to use a registry key and a pop up. Use the pop up once and get the user to input their new username on the new system. Then store that information in the registry. Have your login script check for the registry key. If it exists, read the information for the drive mapping. If the key does not exist then prompt the user with an input box for the needed information.

A down side I see to this all no matter what is the security. If you have locked down the folders then you are going to have some difficulties unless you have already matched things up with security.

Using ADMT as I suggested earlier, the SIDs for the users would be the same so you would not need to combat the NTFS issues.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
dsquery can create that list for you. It has a DisplayName property. Place the following in a cmd file:
Code:
dsquery * ou=whatever,ou=your,ou=situation,dc=requires,dc=org -filter "(&(objectclass=user)(objectcategory=person))" -attr displayName sAMAccountName

Then run that cmd file and redirect its output to a file:
Code:
test.cmd>>test.txt
That will create a text file with users' display name as the first column and the users' SAM account name as the second column.

You can then iterate through that list in .vbs.

hth.

"We must fall back upon the old axiom that when all other contingencies fail, whatever remains, however improbable, must be the truth." - Sherlock Holmes

 
Good suggestion lawnboy. He would need to run that on each forest, then merge the two lists together based on the display name.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top