Skip to content
Home » Windows » Scripting Windows sysadmin tasks

Scripting Windows sysadmin tasks

I mentioned a couple of days ago a coworker’s philosophy about sysadmins and scripts that automate most tasks.

Here’s a site that has a lot of useful one-liners.

And Rob Vander Woude’s site touches on this, but the FOR command is something I wish I’d learned and mastered in 1998, rather than whenever it was I learned it.

Sometimes you have to do something repetitive, like copy a file out to every server, or worse yet, every computer on the network.

A real-world example: My boss came to me one day and said that a client needed a font installed on every computer, and they wanted it done that day. He said he already told them that was impossible. And I said that actually it wasn’t. A job like that should take less than an hour if the network cooperates.

The trick is something like this:

for %%i in (big list of computers here) do copy font.ttf \\%%i\c$\windows\fonts

Even generating that list of computers isn’t all that difficult. It’s not obvious, by any stretch, but Mr. Vander Woude gives a couple of options for that, too. I do it with net view and a pipe. Scroll to the middle of this entry for an example.

I once had a canned script like this that copied antivirus definitions out. That way, if I noticed a server wasn’t getting updates automatically, I could run that, blast out the update so it was protected and up to date, and then I could figure out why the server wasn’t getting the updates and address that problem.

Some of my own scripts

I thought I’d share a few of my own scripts with you. Feel free to adopt them and adapt them to your own needs.

Also, here’s how to avoid invalid global switch errors when running WMIC. And sometimes when you’re writing a script you need more than one command per line.

If you found this post informative or helpful, please share it!

1 thought on “Scripting Windows sysadmin tasks”

Comments are closed.

%d bloggers like this: