Change Media Pool using powershell

PowerShell script exchange

Change Media Pool using powershell

Veeam Logoby villegente » Thu Apr 17, 2014 5:22 am


I have 2 media pool (weekly, monthly) and one backup to tape job. The job run every saturday.
I want use the media pool monthly the last saturday of the month and the media pool weekly for the other saturday.

I have try several command without success.
How can I create a script that will look if it is the last saturday of the month, select the good media pool and start the job ?

Posts: 3
Liked: never
Joined: Thu Sep 12, 2013 4:48 am
Full Name: Olivier VILLEGENTE

Re: Change Media Pool using powershell

Veeam Logoby v.Eremin » Thu Apr 17, 2014 9:26 am

Hi, Olivier,

At the moment, it's not possible to change settings of tape jobs via PowerShell. Though, we're working on it.

As to your scenario, you would need to have two different media pools (weekly, monthly) and two different tape jobs pointed to them in accordance (1st -> weekly; 2nd -> monthly). Being scheduled via Windows Scheduler to run on every Saturdays, the script will check whether the given Saturday is the last Saturday of the month and execute appropriate tape job (weekly or monthly one).

You can use custom function that finds the last X day of the month. The script should be similar to the following:
Code: Select all
    Function Get-LastxOfMonth {           
    Begin {           
        $alldays = @()           
    Process {           
        # Validate the Day string passed as parameter by casting it into           
        if (-not([System.DayOfWeek]::$Day -in 0..6)) {           
            Write-Warning -Message 'Invalid string submitted as Day parameter'           
        Switch ($PSCmdlet.ParameterSetName)           
            ByString {           
                # Do nothing, variables are already defined and validated           
            ByDate   {           
                $Month = $Date.Month           
                $Year = $Date.Year           
        # There aren't 32 days in any month so we make sure we iterate through all days in a month           
        0..31 | ForEach-Object -Process {           
            $evaldate = (Get-Date -Year $Year -Month $Month -Day 1).AddDays($_)           
            if ($evaldate.Month -eq $Month)           
                if ($evaldate.DayOfWeek -eq $Day) {           
                    $alldays += $evaldate.Day           
        # Output           
        if ($asDate) {           
            Get-Date -Year $Year -Month $Month -Day $alldays[-1]           
        } else {           
    End {}           
    $Job1 = Get-VBRTapeJob -name "Name of first tape Job"
    $Job2 = Get-VBRTapeJob -name "Name of second tape Job"
    $Date = Get-Date
    $LastSaturday = Get-LastxOfMonth -Day Saturday -Month $Date.Month -Year $Date.Year
    if ($Date.Day -eq $LastSaturday)
    Start-VBRJob -Job $Job2
    Else {Start-VBRJob -Job $Job1

Veeam Software
Posts: 14019
Liked: 1051 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Return to PowerShell

Who is online

Users browsing this forum: Dsgrievew and 1 guest