PowerShell script exchange
Post Reply
raymix
Influencer
Posts: 19
Liked: 2 times
Joined: Jun 01, 2016 2:20 pm
Full Name: Raimonds Virtoss
Contact:

Powershell and GFS schedules

Post by raymix » Aug 20, 2018 12:03 pm

Hi guys
I am trying to figure out how to determine what the next Tape backup job will be using powershell. The script will be run after the tape job is finished to determine what kind of tapes goes offline and what tapes by label has to come online.
The reason for this is tape naming scheme - 001W, 001M, 001Q and 001Y.

Question is - what date format is VBR using to determine first, second, third, fourth and last week of month, quarter and year?
Is it ISO8601?

This is what I got so far, but I read that -UFormat %V (Unix format for ISO) is not reliable
WeeklyOptions : Tuesday 00:00:00
MonthlyOptions : Fourth Tuesday of the month
QuarterlyOptions : Fourth Tuesday of the quarter
YearlyOptions : Fourth Tuesday of the year

Code: Select all

$tapeJob = Get-VBRTapeJob -Name "GFS Tape job"
$tapeJobNextRun = $tapeJob.NextRun
$tapeJobSchedule = $tapeJob.GFSScheduleOptions

$tapeGFSWeekly = $tapeJobSchedule.WeeklyOptions
$tapeGFSMonthly = $tapeJobSchedule.MonthlyOptions
$tapeGFSQuarterly = $tapeJobSchedule.QuarterlyOptions
$tapeGFSYearly = $tapeJobSchedule.YearlyOptions

function parseToNumeric($down) {
    $result = switch ($down)
    {
        "First"    {1}
        "Second"   {2}
        "Third"    {3}
        "Fourth"   {4}
        "Last"     {5}
    }
    return $result
}

$isYearly = (Get-date $tapeJobNextRun -UFormat %V) -eq (parseToNumeric $tapeGFSYearly.DayOfWeekNumber)
Perhaps there is a better way to extract dateTime from GFS schedules other than parsing this stuff manually from strings?

raymix
Influencer
Posts: 19
Liked: 2 times
Joined: Jun 01, 2016 2:20 pm
Full Name: Raimonds Virtoss
Contact:

Re: Powershell and GFS schedules

Post by raymix » Aug 20, 2018 2:42 pm

Let me rephrase question about ISO a bit to hopefully make more sense.

Does VBR consider below when running schedules?
Year starts with 1st January
Monday is first day of week

raymix
Influencer
Posts: 19
Liked: 2 times
Joined: Jun 01, 2016 2:20 pm
Full Name: Raimonds Virtoss
Contact:

Re: Powershell and GFS schedules

Post by raymix » Aug 21, 2018 10:23 am

Was on the phone with Victor and he confirmed that such settings shouldn't be hardcoded and most likely uses local culture dynamically, which makes sense.

For anyone looking for a generic PowerShell function to determine week of year, see below.

Code: Select all

function Get-WeekNumber([datetime]$DateTime = (Get-Date)) {
    $cultureInfo = [System.Globalization.CultureInfo]::CurrentCulture
    $cultureInfo.Calendar.GetWeekOfYear($DateTime,$cultureInfo.DateTimeFormat.CalendarWeekRule,$cultureInfo.DateTimeFormat.FirstDayOfWeek)
}

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests