Endpoint Insights
PowerShell Script with AfterBackup.bat in ConfigMgr 2012 and 2007

Receive notification right in your inbox whenever new content like this is released & sign up for our email list!
We’ll send you the latest updates, how-to’s, and solutions to empower you at every endpoint.
By signing up you agree to our Privacy Policy.
In 2011, I created a batch file to keep 7 days’ worth of a Configuration Manager backup directory on another server (http://smsug.ca/blogs/garth_jones/archive/2011/01/13/afterbackup-bat.aspx).
This batch file makes one directory for each day of the week using the first 3 characters of the date format. It still works great, but only if your date format is the same as the one below (mm-dd-yy). This happens to be the default date format in the US.
However, it won’t work if your date format is different, such as the one below (yy-mm-dd). This is the default date format in Canada.
While working with a colleague, Damien Redhead, he suggested that the easiest solution to having my batch file work with any date format was to convert it to a PowerShell script; enabling it to work with any date format.
I’m not a big fan of PowerShell, so I asked Damien to write the script for me. Damien doesn’t have a blog, so I agreed to post the PowerShell script for him.
You’ll see below that Backup.ps1 performs the same tasks as my old batch file. It copies the ConfigMgr 2012 or ConfigMgr 2007 backup directory to another network share and keeps 7 days’ worth of backups. You then launch the PowerShell script from the afterbackup.bat; the command line is listed below.
AfterBackup.bat
@ECHO OFF
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -nologo -command “. ‘E:\Program Files\Microsoft Configuration Manager\inboxes\smsbkup.box\backup.ps1′”
Backup.ps1
##############################################################
## Author: Damien Redhead ##
## Date: December 02, 2014 ##
## Purpose: Transfer local backup of SCCM to remote server##
##############################################################
$currentDay = (Get-Date).dayofweek
$localPath = “E:\CMBak\*”
## Send to FSP
$remotePath = “\\ServerName\CMBak\$currentDay\Site Code\“
if (Test-Path -Path $remotePath)
{
Remove-Item -Recurse -Force $remotePath
}
copy-item $localPath $remotePath -force -recurse -verbose
Related Resources

Customer Stories: Endpoint Insights Enables Powerful Device Warranty Management for Carr, Riggs & Ingram



Better Together: Endpoint Insights and Right Click Tools Webinar Highlights






Endpoint Insights: Create a Collection of Computers with a Specific Docking Station






Use Endpoint Insights to Budget with Confidence, Gain Asset Insights, and Stay Ahead of Issues





















