Skip to main content

Automation can start small: PowerShell jobs creation


Rick Vanover
Forum|alt.badge.img+10

I’ll be the first to admit that I’m not an automation expert. That being said, I also like to start small, and one area I’d think is a good area for many is PowerShell. For Veeam Backup & Replication, I’d like to draw your attention to the PowerShell User Guide: https://helpcenter.veeam.com/docs/backup/powershell/getting_started.html?ver=110

 

This is a great place to start with PowerShell and for a small task like creating jobs, it’s so easy even Rick Vanover can do it. Take for example this 5-line PowerShell script:

 

$repository = Get-VBRBackupRepository -Name "NAS"

$TagsOnlyWayToGo = Find-VBRViEntity -Name "fwu-Engineering" -Tags

Add-VBRViBackupJob -Name "__FWU Backup - Engineering" -BackupRepository $repository -Entity $TagsOnlyWayToGo -Description "Provider level backup job of Engineering - 24h RPO"

Set-VBRJobSchedule -Job "__FWU Backup - Engineering" -Periodicaly -FullPeriod 24 -PeriodicallyKind Hours

Enable-VBRJobSchedule -Job "__FWU Backup - Engineering"

 

You also may have/want to add this string to get PowerShell going:

Add-PSSnapin VeeamPSSnapin
Connect-VBRServer 

 

Once your session is active, the simple 5-line script will create a job, let me walk through each line:

$repository = Get-VBRBackupRepository -Name "NAS"

I have a pre-defined backup repository called “NAS” and this is the target for my backup job to go to.

 

$TagsOnlyWayToGo = Find-VBRViEntity -Name "fwu-Engineering" -Tags

 

I may be a bit boasty, indicating that for this VMware backup job - vSphere Tags are the only way to go and I’m adding to the job a tag type called “fwu-Engineering” and any VM or other object tagged with that will be put in the job. Easy-peasy.

Add-VBRViBackupJob -Name "__FWU Backup - Engineering" -BackupRepository $repository -Entity $TagsOnlyWayToGo -Description "Provider level backup job of Engineering - 24h RPO"

I gave the job a name here, and a description. Use the descriptions here, makes troubleshooting a bit easier later.

Set-VBRJobSchedule -Job "__FWU Backup - Engineering" -Periodicaly -FullPeriod 24 -PeriodicallyKind Hours

I am not too particular on the job other than I want it to run every 24 hours; and I set that here.

Enable-VBRJobSchedule -Job "__FWU Backup - Engineering"

Enable the job and go!

 

I have done a few demos where I was able to quickly onboard backups for a number of different tags, one job per tag quite easily. I like PowerShell job creation as it can ensure they are consistently done and is a quick and easy way to do it. 

Like I said - I’m no Automation Guru but the beauty about Veeam here is you can start small, as simple as jobs and build on that. Let me know if you’ve ever done a PowerShell job creation.

10 comments

mkevenaar
Forum|alt.badge.img+15
  • Veeam Vanguard
  • 149 comments
  • November 22, 2022

Would you look at that, Mr. RICKATRON doing automation! 

 

Thank you for sharing this post and the explanation for the steps


Rick Vanover
Forum|alt.badge.img+10
  • Author
  • RICKATRON
  • 765 comments
  • November 22, 2022
mkevenaar wrote:

Would you look at that, Mr. RICKATRON doing automation! 

 

Thank you for sharing this post and the explanation for the steps

I try man. I admire what you do @mkevenaar in this area! I can only go up from here.


vAdmin
Forum|alt.badge.img+2
  • Influencer
  • 168 comments
  • November 22, 2022

Yes, this is one of the strength and reason why Veeam is better at the automation, it has the PowerShell commands to do some stuff not just reporting :-)

 

Thanks @Rick Vanover for sharing the info here.


mkevenaar
Forum|alt.badge.img+15
  • Veeam Vanguard
  • 149 comments
  • November 22, 2022
Rick Vanover wrote:
mkevenaar wrote:

Would you look at that, Mr. RICKATRON doing automation! 

 

Thank you for sharing this post and the explanation for the steps

I try man. I admire what you do @mkevenaar in this area! I can only go up from here.

No! Try not! Do or do not, there is no try. - Yoda

 


Geoff Burke
Forum|alt.badge.img+22
  • Veeam Legend, Veeam Vanguard
  • 1314 comments
  • November 22, 2022
mkevenaar wrote:

Would you look at that, Mr. RICKATRON doing automation! 

 

Thank you for sharing this post and the explanation for the steps

He has shamed me into action :)> I am going to start the Ansible course at KodeKloud now which was originally further down my list! 


Chris.Childerhose
Forum|alt.badge.img+21
  • Veeam Legend, Veeam Vanguard
  • 8436 comments
  • November 22, 2022

Always love PowerShell for doing many things.  With Veeam it works great to change settings and like this create a job. Going to get more in to this and hopefully post back here with some things. 👍


Markus.K1985
Forum|alt.badge.img+3
  • Comes here often
  • 8 comments
  • December 9, 2022

Also have a look at this project: https://github.com/vMarkusK/VeeamJobConfig

I used this for Mass Configuration from Reference Job.


Chris.Childerhose
Forum|alt.badge.img+21
  • Veeam Legend, Veeam Vanguard
  • 8436 comments
  • December 9, 2022
Markus.K1985 wrote:

Also have a look at this project: https://github.com/vMarkusK/VeeamJobConfig

I used this for Mass Configuration from Reference Job.

That is very cool and I will be checking that out for some possible automation. 😎


JHoughes
Forum|alt.badge.img+2
  • Veeam Vanguard
  • 19 comments
  • December 12, 2022

Not to just tag on to your content Rick, but I may have seen someone perform a demo or 2 around this before also.  😉

I covered this in my VeeamON 2020 session video along with some explanation, for those who want to watch and follow along:

Script: NewBackupShellJob.ps1 (GitHub)
Video: 



Also, if anyone needs to be able to run some quick job comparisons by selecting a job to be your reference point, check out these scripts I wrote for VeeamON 2020 demos:

Get-VeeamJobConfiguration.ps1 (GitHub)

Run-VeeamJobComparison.ps1 (GitHub)

 

If you want to see the video on how to use these scripts separately or in a pipeline, along with some quick background on advance functions check here:
 


Cheers, hope it helps someone out.


Chris.Childerhose
Forum|alt.badge.img+21
  • Veeam Legend, Veeam Vanguard
  • 8436 comments
  • December 12, 2022

Thanks for sharing those, Joe.  Always good to have automation content available.  😁