Solved

VBS Script to copy files with permissions

Posted on 2008-10-28
5
744 Views
Last Modified: 2008-10-29
One of our techs was pointing a bunch of users to their home directory in Active Directory by highlighting all users, and using the variable %username% at the end. Unfortunately, they accdidentally left a "j" infront of the %username%. So now every user has a j infront of their home folder name. I dumped a list of all users home directorys, and wrote a script to check for the j, then copy the contents from the folder with the j, to the folder without the j.

Everything works fine, except its not copying over the folder/file permissions. I can't seem to find an option to do that with the method I am using. I have also looked into using robocopy.exe from the resource kit, but had some issues. I think my script is much simpler, if I could only get it to copy permissions.

Here is my script:

Dim objFSO


Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile ("c:\scripts\users.txt", 1)

Set objShell = CreateObject("Wscript.Shell")

Do Until objTextFile.AtEndOfStream
      strHD = objTextFile.Readline

      If objFSO.FolderExists("c:\scripts\users\j"+strHD) then
            set copyHD = objFSO.GetFolder("c:\scripts\users\j"+strHD)
            copyHD.Copy("c:\scripts\users\"+strHD)
            objFSO.DeleteFolder("c:\scripts\users\j"+strHD)
      end if

Loop

If anyone has any ideas that wold be great!
0
Comment
Question by:colesy
  • 3
  • 2
5 Comments
 
LVL 16

Expert Comment

by:robrandon
ID: 22825583
If you rename the folder instead, and the folder is on the same drive, the permissions will remain intact.

Not sure how to copy the permissions in VB.
0
 
LVL 16

Expert Comment

by:robrandon
ID: 22825600
Duh, renaming would keep it in the same location.....

If you move it to a new name, so long as it moves within the same drive it will maintain the permissions.

Anyway, maybe just rename the folder.
0
 

Author Comment

by:colesy
ID: 22825719
hmm I never thought about renaming.. That makes more sense. I will give that a shot.. Thanks.
0
 

Author Comment

by:colesy
ID: 22826036
It turns out renaming won't work. The tech already changed the home directories to be correct, so users have two folders. Some work is in the folder with a j and some in the correct one. They don't have access to the j folder.

After I realized this, I shouldn't have to worry about permissions. The folders should already have the right permissions, and I should just be able to copy the content over.
0
 
LVL 16

Accepted Solution

by:
robrandon earned 250 total points
ID: 22830306
Are you set then?  I'm not sure what you meant in your last paragraph.

If not, you could always migrate back to the J folder (with the correct permissions), remove the replacement non-J folder, then rename the original.

You'll have to determine which is easier, that, or somehow copying the permissions over to the new folder.

0

Featured Post

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

As network administrators; we know how hard it is to track user’s login/logout using security event log (BTW it is harder now in windows 2008 because user name is always “N/A” in the grid), and most of us either get 3rd party tools, or just make our…
Mapping Drives using Group policy preferences Are you still using old scripts to map your network drives if so this article will show you how to get away for old scripts and move toward Group Policy Preference for mapping them. First things f…
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now