Now, before I get inundated with “Don’t use ConfigMgr Backup, SQL Backup is where it is at…” let me say, I agree with this to a point. You should be using SQL Backup for a variety of reasons the primary of which is Data Compression – ConfigMgr Site Backup Maintenance Task doesn’t Compress the Database, so if you are doing daily backups that will chew up a lot of disk space. I also recommend doing a Weekly Site Backup using the Maintenance Task to get “outliers”, CD.Latest Folder, Registry Settings, Inboxes. The Database is the only thing that needs to be backed up daily, so throw a Site Maintenance Task to run just prior to the Full SQL Backup (not to interfere with Differentials) and you will make sure to have everything you need to recover your Site.
I had a customer who wanted to use the Configuration Manager Backup but wanted to run a PowerShell script after the backup – I directed them to the AfterBackup.bat file which will automatically run after the backup tasks successfully completed. Their enthusiasm was notably absent as and I quote “Batch Files are so 1990, doesn’t Microsoft know it is 2020?”
Arguments of what year it is aside, this is the hand we are dealt, and it is quite simply addressed.
Here is an example of an AfterBackup.bat which will call a PowerShell Script AfterBackup.ps1 in the same folder as %~dp0
represent the current execution directory.
@ECHO OFF
%WinDir%\System32\WindowsPowerShell\v1.0\powershell.exe -nologo -command ". '%~dp0AfterBackup.ps1'"

So, now that we have placed a AfterBackup.bat and AfterBackup.ps1 in the smsbkup.box folder this will executes the Batch File, which subsequently launch the PowerShell Script, once the Backup Maintenance Task successfully complete.

I like putting these two files in the same folder for security reasons, remember AfterBackup.bat and all subsequent processes (PowerShell Script, and anything the PowerShell Script Executes) run as System, so you want to be careful what you put in these files.

So, this is how you can have a PowerShell Script run after the Configuration Manager Site Backup Maintenance Task successfully completed.
You must log in to post a comment.