Skip to content
Menu
The Lonely Administrator
  • PowerShell Tips & Tricks
  • Books & Training
  • Essential PowerShell Learning Resources
  • Privacy Policy
  • About Me
The Lonely Administrator

WBADMIN Demo

Posted on July 27, 2010May 18, 2015

Earlier this year I wrote an article for REDMOND Magazine about the new backup features in Windows Server 2008 R2. I'm not going to re-hash the article here except to say it includes some sample scripts on using the WBADMIN command line tool. One of the scripts is an old-school batch file.

Manage and Report Active Directory, Exchange and Microsoft 365 with
ManageEngine ADManager Plus - Download Free Trial

Exclusive offer on ADManager Plus for US and UK regions. Claim now!

The batch file included code to create a directory that included a time stamp, like \\mycompany-dc01\backup\RESEARCHDC\12152009_132532 where the last portion is the month, day, year, hour, minute and second. My original code parsed out these values from the %TIME% variable.

set m=%date:~4,2%
set d=%date:~7,2%
set y=%date:~10,4%
set h=%time:~0,2%
set min=%time:~3,2%
set sec=%time:~6,2%

Unfortunately, I forgot to take into account situations where the time mght not have two digits like 1:00AM. In those situations the code tries to create a folder like \\mycompany-dc01\backup\RESEARCHDC\12152009_ 10000 which fails because of the space. To correct this I needed to add a line to check for the space in the variable, %h% and if found, define a new value with a leading 0.

rem handle blanks in hour
if /i %h:~0,1%$==$ set h=0%h:~1,1%

This sort of thing is much, much easier in Windows PowerShell, by the way. But regardless, I now have an updated batch file.
[cc lang="DOS"]

@echo off
::Demo-Backup.bat
::demonstration script using WBADMIN.EXE on a Windows Server 2008 R2 Server
::http://redmondmag.com/Articles/2010/04/01/Backup-Basics-in-Windows-Server-2008-R2.aspx?Page=1
::Revised 9:58 AM 7/26/2010

set backupshare=\\File01\backups

rem files and folders to include
set include=c:\scripts,c:\work

set m=%date:~4,2%
set d=%date:~7,2%
set y=%date:~10,4%
set h=%time:~0,2%
set min=%time:~3,2%
set sec=%time:~6,2%

rem handle blanks in hour
if /i %h:~0,1%$==$ set h=0%h:~1,1%

rem defining a new folder like \\mycompany-dc01\backup\RESEARCHDC\12152009_132532

set newfolder=%backupshare%\%computername%\%m%%d%%y%_%h%%min%%sec%

echo Creating %newfolder%

mkdir %newfolder%

rem run the backup
echo Backing up %include% to %newfolder%

wbadmin start backup -backuptarget:%newfolder% -include:%include% -quiet

rem Clear variables
set backupshare=
set include=
set m=
set d=
set y=
set h=
set min=
set sec=
set newfolder=

::EOF

You can download the batch file here. Rename it to .bat.


Behind the PowerShell Pipeline

Share this:

  • Click to share on X (Opens in new window) X
  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on Mastodon (Opens in new window) Mastodon
  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to share on Pocket (Opens in new window) Pocket
  • Click to share on Reddit (Opens in new window) Reddit
  • Click to print (Opens in new window) Print
  • Click to email a link to a friend (Opens in new window) Email

Like this:

Like Loading...

Related

1 thought on “WBADMIN Demo”

  1. Pingback: Tweets that mention WBADMIN Demo | The Lonely Administrator -- Topsy.com

Comments are closed.

reports

Powered by Buttondown.

Join me on Mastodon

The PowerShell Practice Primer
Learn PowerShell in a Month of Lunches Fourth edition


Get More PowerShell Books

Other Online Content

github



PluralSightAuthor

Active Directory ADSI Automation Backup Books CIM CLI conferences console Friday Fun FridayFun Function functions Get-WMIObject GitHub hashtable HTML Hyper-V Iron Scripter ISE Measure-Object module modules MrRoboto new-object objects Out-Gridview Pipeline PowerShell PowerShell ISE Profile prompt Registry Regular Expressions remoting SAPIEN ScriptBlock Scripting Techmentor Training VBScript WMI WPF Write-Host xml

©2025 The Lonely Administrator | Powered by SuperbThemes!
%d