Get time in hours from schedule

PowerShell script exchange

Get time in hours from schedule

Veeam Logoby ldasilva » Wed 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
ldasilva
Novice
 
Posts: 5
Liked: never
Joined: Tue Apr 25, 2017 5:43 pm
Full Name: Lisandro da Silva

Re: Get time in hours from schedule

Veeam Logoby v.Eremin » Thu 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.
v.Eremin
Veeam Software
 
Posts: 13296
Liked: 974 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Get time in hours from schedule

Veeam Logoby ldasilva » Fri 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
ldasilva
Novice
 
Posts: 5
Liked: never
Joined: Tue Apr 25, 2017 5:43 pm
Full Name: Lisandro da Silva

Re: Get time in hours from schedule

Veeam Logoby v.Eremin » Fri 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.
v.Eremin
Veeam Software
 
Posts: 13296
Liked: 974 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Get time in hours from schedule

Veeam Logoby SRedlin » Tue 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()
SRedlin
Novice
 
Posts: 8
Liked: never
Joined: Fri Sep 23, 2016 10:20 am
Full Name: Stefan Redlin

Re: Get time in hours from schedule

Veeam Logoby v.Eremin » Tue 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.
v.Eremin
Veeam Software
 
Posts: 13296
Liked: 974 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin


Return to PowerShell



Who is online

Users browsing this forum: No registered users and 9 guests