PowerShell script exchange
Post Reply
ldasilva
Novice
Posts: 5
Liked: never
Joined: Apr 25, 2017 5:43 pm
Full Name: Lisandro da Silva
Contact:

Get time in hours from schedule

Post by ldasilva » Apr 26, 2017 9:00 pm

Hi,

How can i retrieve only the time of the schedule and not the complete date and time?

Example

$jobOptions | Add-Member -MemberType NoteProperty -Name "Time" -value $job.ScheduleOptions.get_NextRun()

This returns the date and time.

and when i try this one

$jobOptions | Add-Member -MemberType NoteProperty -Name "Time" -value $Job.ScheduleOptions.OptionsDaily.kind

nothing happens

Please help

v.eremin
Product Manager
Posts: 16342
Liked: 1344 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Get time in hours from schedule

Post by v.eremin » Apr 27, 2017 10:08 am

Try this script and see whether it answers your requirements:

Code: Select all

Asnp VeeamPSSnapin
$BackupJob = Get-VBRJob -Name "Name of your Job"
$Date = Get-Date $BackupJob.ScheduleOptions.NextRun
$Date.ToShortTimeString()
Thanks.

ldasilva
Novice
Posts: 5
Liked: never
Joined: Apr 25, 2017 5:43 pm
Full Name: Lisandro da Silva
Contact:

Re: Get time in hours from schedule

Post by ldasilva » Apr 28, 2017 12:14 pm

Hi Eremin,

Thank you for your reply.

When i added this to my script, it does populate the time, however i do get an error msg

Code: Select all

"Get-Date : Cannot bind parameter 'Date'. Cannot convert value "" to type "System.DateTime". Error: "String was not reco
gnized as a valid DateTime."
At C:\tmp\collection.ps1:20 char:33
+                 $time = get-date <<<<  $job.ScheduleOptions.get_NextRun()
    + CategoryInfo          : InvalidArgument: (:) [Get-Date], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.GetDateCommand"

This is what i added in my script

Code: Select all

$time = get-date $job.ScheduleOptions.get_NextRun()

$jobOptions | Add-Member -MemberType NoteProperty -Name "Time" -value $time.ToShortTimeString()
kind regards,

Lisandro

v.eremin
Product Manager
Posts: 16342
Liked: 1344 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Get time in hours from schedule

Post by v.eremin » Apr 28, 2017 2:55 pm

There is no such method as get_NextRun(). So, the result of $job.ScheduleOptions.get_NextRun() line is $Null which cannot be converted to DateTime format. Kindly, leverage the code I suggested. Thanks.

SRedlin
Influencer
Posts: 10
Liked: 1 time
Joined: Sep 23, 2016 10:20 am
Full Name: Stefan Redlin
Contact:

Re: Get time in hours from schedule

Post by SRedlin » May 02, 2017 9:14 am

This lines of code display the output wanted.

Code: Select all

$time = get-date $BackupJob.ScheduleOptions.OptionsDaily.TimeLocal 
$time.ToShortTimeString()

v.eremin
Product Manager
Posts: 16342
Liked: 1344 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Get time in hours from schedule

Post by v.eremin » May 02, 2017 11:23 am

The problem I can see with the last example is the fact that it works only for jobs with daily type of schedule, and it doesn't take backup window settings into account. So, keep this in mind, if you stick to this script. Thanks.

Post Reply

Who is online

Users browsing this forum: Exabot [Bot] and 12 guests