Solved

VBS Script to copy files with permissions

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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

A hard and fast method for reducing Active Directory Administrators members.
After seeing many questions for JRNL_WRAP_ERROR for replication failure, I thought it would be useful to write this article.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

696 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