Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to find a one-size fits all wbadmin script that I can deploy to a variety of Server 2008 R2 servers.

The catch I'm having is that whilst all of the servers have a C:, some have an E:, some an E: and an F: and some have just an F:.

The following command:

wbadmin enable backup -addtarget:\\backup1\Backups -schedule:23:00 -systemState -allCritical -vssFull -user:backupservice@domain.local -password:ladidada -quiet

Only backs up the C: and I don't see any options in wbadmin to back up all the local drives. And of course, if I try shoot the problem with a machine gun (by adding -include:c:,d:,e:,f:...etc) then we get ERROR - The path specified by 'g:' was not found.

Please don't tell me that I have to enumarate all the local drives and do it that way. Is there ANY way to tell wbadmin to include all local drives when backing up?

share|improve this question
up vote 2 down vote accepted

Here's a variation that automatically avoids cd/dvd. It deliberately backs up hard drives only.

@echo off


set remotebackup=\\backupserver\path

for /F "usebackq eol=: skip=1 tokens=1" %%a in (
  `wmic logicaldisk where "drivetype=3" get deviceid`
) do (
  set "_drive=%%a:"
  set "_HDL=!_HDL!!_drive:~0,2!,"
if "%_HDL:~-1%"=="," (set _HDL=%_HDL:~0,-1%)
if "%_HDL:~-2%"==",:" (set _HDL=%_HDL:~0,-2%)

echo Found: %_HDL%

wbadmin start backup -backuptarget:%remotebackup% -include:!_HDL! -allCritical -vssCopy -quiet -systemState

This forms part of a scheduled task which is why wbadmin start is used rather than wbadmin enable.

The bits of interest here are "drivetype=3" and using usebackq (required).

Mark's code was helpful in tracking this down.

The if statements remove the last comma or comma and colon if they exist. Couldn't think of an easier way to do this. %%a is copied into _drive so it can be trimmed to the first 2 characters (C:) using the :~0,2 syntax.

share|improve this answer
Moving the checkmark to your answer because it's more elegant than mine :) – Mark Henderson Oct 3 '11 at 21:14

while a solution which looked up the list of drives from wmi would be better. If you know you only have e: f: and g: then this will work fine

set wbinclude=
if exist e:\*.* set wbinclude=e:\
if exist f:\*.* set wbinclude=%wbinclude% f:\
if exist g:\*.* set wbinclude=%wbinclude% f:\
if not "%wbinclude%"=="" set wbinclude=-includes %wbinclude%

echo wbadmin enable backup -addtarget:\\backup1\Backups -schedule:23:00 -systemState -allCritical -vssFull -user:backupservice@domain.local -password:ladidada -quiet %wbinclude%
share|improve this answer
Thanks. Unfortunately they're not all the drives, they're all spread over the place. I posted my own script as an answer above which does what you suggested. – Mark Henderson Apr 14 '11 at 2:36

After a heap of mucking around (I hate DOS batching), I've come up with the following. It seems to work well:

@echo off


FOR /f %%I IN (
 'wmic volume get driveletter'
) DO (
  ECHO %%I | FIND ":"
   echo Failed: %%I
  ) ELSE (
   ECHO %%I | FIND "D:"
    ) ELSE (
      echo Skipping CD-ROM


wbadmin enable backup -addtarget:\\backupserver\Backups -schedule:23:00 -systemState -allCritical -vssFull -user:backupservice@domain.local -password:1234password -quiet -include:!_TEMPVAR!

A dissection is:

The first part of the batch finds all the drive letters from wmic volume get driveletter. It checks to see that each line is actually a valid drive letter (as the output includes some verbose information that we don't need) by checking for the : character.

Then, it checks to see if the drive is the D: as in my situation these are all optical drives, which cause errors when specified in wbadmin and skips them.

Then, it checks to see if the string has content in it. If it does, it suffixes a comma (,). If the string is blank, it doesn't do anything.

Then, it goes and appends the drive letter to the the variable.

The, it execudes wbadmin:

  • wbadmin enable backup - specifies that we want to set up a Windows Backup schedule
  • -addtarget:\\enetsbackup1\Backups - I want to back up to a network location, so I'm specifying it here.
  • -schedule:23:00 - I want the backups to run at 11pm each night
  • -systemState - I want the system state included for bare metal restores
  • -allCritical - I want all critical system drives included (this is important because the above script only builds visible drive letters. There may be partitions that need backing up in order to boot the server that do not have drive letters)
  • -vssFull - This is the only backup we're doing on this server, so tell Windows Backup to reset the archived bit.
  • -user:backupservice@domain.local - This is the account that's a member of the Backup Operators group on the domain (and also neeeds to be in the local Backup Operators group as well. This is very poorly document by Microsoft)
  • -password:1234password - The password for the backup service account
  • -quiet - Do not make any prompts. I'm going to be running this as a startup script in a group policy, so prompts are bad.
  • -include:!_TEMPVAR! - This is the most critical part. It specifies which drives should be backed up, and includes the string of drives we collected earlier.

And just to confirm it's worked, to check it in the GUI:

Result of wbadmin command

Things that can probably be improved: Instead of running from drive letters, the drive GUID might be a smarter idea, because this won't back up drives that are not mounted with drive letters. So if you've mounted a disk inside an NTFS partition, or the drive doesn't have a drive letter for whatever reason, it will be skipped.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.