PowerShell script exchange
Post Reply
villegente
Novice
Posts: 3
Liked: never
Joined: Sep 12, 2013 4:48 am
Full Name: Olivier VILLEGENTE
Contact:

Change Media Pool using powershell

Post by villegente »

Hi,

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 ?

Thanks,
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Change Media Pool using powershell

Post by veremin »

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 {           
    [CmdletBinding()]           
    param(           
        [parameter(Mandatory)]           
        [String]$Day,           
               
        [parameter(ParameterSetName='ByDate',Mandatory,ValueFromPipeline)]           
        [System.DateTime]$Date,           
               
        [parameter(ParameterSetName='ByString',Mandatory,ValueFromPipelineByPropertyName)]           
        [ValidateRange(1,12)]           
        [int]$Month,             
        [parameter(ParameterSetName='ByString',Mandatory,ValueFromPipelineByPropertyName)]           
        [ValidatePattern('^\d{4}$')]           
        [int]$Year,           
               
        [switch]$asDate=$false           
    )           
    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'           
            return           
        }           
               
        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 {           
            $alldays[-1]           
        }           
    }           
    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
    } 
Thanks.
Post Reply

Who is online

Users browsing this forum: bct44 and 32 guests