?
Solved

VBS Script to copy files with permissions

Posted on 2008-10-28
5
Medium Priority
?
752 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 750 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here's a look at newsworthy articles and community happenings during the last month.
After seeing many questions for JRNL_WRAP_ERROR for replication failure, I thought it would be useful to write this article.
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

762 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