I work for an SMB, but we’re past the size where it’s ‘easy’ to go around to everyone’s computers and deploy a new email signature. We also have prescribed branding, but staff inevitably will find a font they like better for their signature and will destroy that branding and consistency without hesitation.

So the other, I finally got around to making things easier for myself. Rather than try to convince everyone to leave their signatures alone, and rather than go around to everyone’s computer and have them login so I can change their signature, I sent out instructions on how to set your signature in Outlook (in Options, under the Mail Format tab), and then hammered out a few lines in to the existing login script:

REM Copy email signature
c:
cd \
if exist %appdata%\Microsoft\Signatures goto COPY
md %appdata%\Microsoft\Signatures
:COPY
cd  %appdata%\Microsoft\Signatures
del *.* /q
copy Q:\Marketing\EmailSignatures\%username%.* .\

The first two lines (after the Remark) make sure that the script is in the root of the C: drive (other parts of the login script not listed here move around, and as we’re deleting files later on with a wildcard it’s worth it to make sure we’re in the right place).

Next, it checks to make sure that the Signatures folder exists. If you’ve already been in to the Signatures area in Outlook it will create the folder for you, however if this is the first time the user is logging in and their profile is just being created, that folder won’t be there, so we make Outlook create it.

After that, we delete the contents of the folder — I can do this because I know that our staff should only be using the one signature. If you’re in an environment where that isn’t the case, this is a Bad Idea.

Finally, we copy the new signature off the shared drive. In this case, we have a plain-text signature and and HTML version, and the filenames are prefixed with the users username, so I can make use of the username environmental variable to automatically select the right files.

The first time the script runs users had to go back in to Signature Options and select the new signature, but after that, because the filename doesn’t change, Outlook will remember the selection and staff will always have a copy of the (correct, consistently-branded) signature.

Like I said, very basic, and there are a few improvements that could be make to the batch script, but it works well enough for me.

ROBOCOPY is an excellent command line utility that Microsoft began bundling with Windows Vista, and has since been included in Windows 7 and Server 2008 (R2 as well). It makes it incredibly simple to mirror a directory tree, and is great for batch file backups. There are a few quirks with it, however.

When using the /MIR switch, ROBOCOPY overwrites the destination path with everything in the source path. To exclude folders, you’re instructed to use the /XD switch. Below is a sample with the correct syntax:

robocopy d:\ n:\Data /MIR /Z /A-:R /R:1 /W:1 /LOG:n:\logs\data.log /XD d:\vms d:\wsus “d:\System Volume Information” d:\tmpbak d:\installs d:\RECYCLER

To break this down, we start with the ROBOCOPY command itself. Following that is the Source Path (D:) and then the Destination Path (N:Data). Next is the /MIR switch that tells ROBOCOPY to mirror the existing directory structure and copy everything. The /Z switch sets the job in Restartable Mode, and /A-:R removes any read-only attributes. /R:1 and /W:1 tell ROBOCOPY to Retry copying the file once if it encounters an error, and Wait one second between retries (I’ve set it this low as the backup runs late at night, as if someone has left a file open it doesn’t matter how many retries are attempted).

Following this, the /LOG switch dumps the full output of the copy job to n:\logs\data.log. This includes information on the number of files copied, directories excluded, etc….

Finally, we get to the /XD switch. Note that this is the last included switch – although you can technically have it where ever you want in the command, it’s cleaner, and less error-prone if you make it the last switch.

To exclude multiple directories, simply list them with spaces in between. If the path contains spaces (in the example above, I’ve excluded System Volume Information), wrap it in double-quotes (“). The most important thing, though, is DO NOT EVER, *EVER* include a trailing “\” in excluded paths!

For some reason, ROBOCOPY parses the trailing “\” in an odd way. If included in the command, the log will list all of the excluded paths, however it will still copy the data. It won’t provide any error messages or other output. For example, if you used the following command:

robocopy d: n:\Data /MIR /Z /A-:R /R:1 /W:1 /LOG:n:logsdata.log /XD d:\vms d:\wsus “d:\System Volume Information\” d:\tmpbak d:\installs d:\RECYCLER

Because there is a trailing \ on “d:\System Volume Information\”, the log will report that the excluded directories are d:\vms d:\wsus d:\System Volume Information d:\tmpbak d:\installs d:\RECYCLER, however it will still attempt to copy all of them.

However, if you simply omit the trailing \, ROBOCOPY will correctly parse the list of paths and will ignore them.