Solved

VBS Script to copy files with permissions

Posted on 2008-10-28
5
746 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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Setting up a Microsoft WSUS update system is free relatively speaking if you have hard disk space and processor capacity.   However, WSUS can be a blessing and a curse. For example, there is nothing worse than approving updates and they just have…
Disabling the Directory Sync Service Account in Office 365 will stop directory synchronization from working.
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 configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

810 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