Monday, July 30, 2012

Script to Copy Specific Folders From One Directory to Another

I had a need to copy specific folders from a folder share to another folder share. I found a script that I had to tweak a little but it will take the contents of a txt file and copy only the folders that you put in it using Robocopy.

For those of you unfamiliar with robocopy, its a copy utility on Windows 7 that has many, many options to copy files and folders from local drives, mapped drives and even UNC paths to a destination path. If you are an old DOS guy like me, just think of xcopy on steroids.

Here is the code:


@echo off
for /F "tokens=*" %%A in (dirlist.txt) do (
  robocopy Y:\%%~A\ Y:\%%~A\ /E /R:1 /W:1 /COPY:DATS
)

Save this to a bat file (ie, copy2dir.bat) and run the bat file. Lets go over the script:

dirlist.txt is where you will put the folder names (new line for each one)

The script will take each line in the txt file, look for a corresponding folder and then copy it to the destination folder. In my case I mapped a shared drive to my Y: drive letter and used that. You could use a UNC path or local drive letter as well.

Robocopy has MANY options. Do a robocopy /? at the command prompt and you will get a listing. The options I chose were:

/E - This copies sub directories, even empty ones.
/R:1 - Retry files only 1 time. the default is literally 1 million times!
/W:1 - Wait only 1 second between tries. Default is 30 seconds
/COPY:DATS - this copies Data, Attributes, Timestamps and Security (NTFS ACLs)

You have many more options to chose from including logging.

Hopefully you may find a use for this simple script.

Friday, July 13, 2012

Granting access to admin$

Recently Microsoft has been taking security serious (well, they are at least trying). For those of you who have installed Exchange 2010 you know what I'm talking about. Previously when installing Windows (or Exchange) everything was wide open. Pretty much an "enable everything, close it later if you don't want it" type of mentality. Lately they have been closing or disabling services, not installing all components unless needed and turning on all software firewalls.

Recently I was installing software from a server that needed to connect to the admin$ share on a computer and install components. So i did my usual:

net share admin$ /users:5


I was able to connect but couldn't make a directory. After looking at the help I needed to add the admin$ share using this command:

net share admin$ /users:5 /grant:username,full


username being either a local or domain username. If using a domain username make sure to put the domain name followed by a backslash and then the username (ie, contesto\bsmith)

User unable to login to RDP Farm after you re-enable them?

We had a strange issue. We had a user leave and since we knew when she was leaving i set the account to expire at a certain date. A couple d...