PowerShell script exchange
Post Reply
skayser
Enthusiast
Posts: 27
Liked: never
Joined: Jul 13, 2010 8:28 am
Full Name: Sebastian Kayser

Working with cmdlets, calling them from a Windows task

Post by skayser »

Hi,

we've got some SureBackup jobs that keep running even after they have finished (sounds strange, I know, I'll open a SR for this). In the meantime the VBR PowerCLI cmdlets came to my mind as a workaround. Idea: simply set up a task that runs every morning and stops the SureBackup jobs. However, Stop-VSBJob throws a InvalidCast exception when fed with output from Get-VSBJob. Has anyone used this successfully?

Code: Select all

PS C:\Users\Administrator> get-vsbjob

Job Name                  State      Last Result  Description
--------                  -----      -----------  -----------
sb-job01                                          Created by VEEAM\Administr...

PS C:\Users\Administrator> get-vsbjob | %{ stop-vsbjob $_ }
Stop-VSBJob : Die angegebene Umwandlung ist ungültig.
Bei Zeile:1 Zeichen:25
+ get-vsbjob | stop-vsbjob <<<<
    + CategoryInfo          : InvalidOperation: (Veeam.Backup.Po...mand.StopVS
   BJob:StopVSBJob) [Stop-VSBJob], InvalidCastException
    + FullyQualifiedErrorId : Backup,Veeam.Backup.PowerShell.Command.StopVSBJo
   b
Once this is working, how can the VBR cmdlets be loaded into a regular PowerShell instance that's started from a scheduled task (via: powershell "<path-to-script>")? Currently they are only available when the PowerShell window is started from within VBR.

Sebastian
Vitaliy S.
VP, Product Management
Posts: 27377
Liked: 2802 times
Joined: Mar 30, 2009 9:13 am
Full Name: Vitaliy Safarov
Contact:

Re: Working with cmdlets, calling them from a Windows task

Post by Vitaliy S. »

Sebastian, to make Veeam B&R PowerShell cmdlets available for scheduled tasks, you should register Veeam PSSnapin with the command below before executing your script:

Code: Select all

PS C:\> Add-PSSnapin VeeamPSSnapIn
skayser
Enthusiast
Posts: 27
Liked: never
Joined: Jul 13, 2010 8:28 am
Full Name: Sebastian Kayser

Re: Working with cmdlets, calling them from a Windows task

Post by skayser »

Cool that helps! Thanks, Vitaliy. Now it's just a question of sorting out why Stop-VSBJob doesn't like being fed by Get-VSBJob. I just tested

Code: Select all

Get-VSBJob | Start-VSBJob
Get-VSBJob | %{ Start-VSBJob $_ }
and both versions works, i.e. VBR begins to start the jobs (one by one). Stop-VSBjob throws the InvalidCast exception in either version.
Vitaliy S.
VP, Product Management
Posts: 27377
Liked: 2802 times
Joined: Mar 30, 2009 9:13 am
Full Name: Vitaliy Safarov
Contact:

Re: Working with cmdlets, calling them from a Windows task

Post by Vitaliy S. »

Sebastian, after consulting to our PowerShell developer, I can say that these cmdlets should work. Could you please open a support ticket regarding PS cmdlets as well?
skayser
Enthusiast
Posts: 27
Liked: never
Joined: Jul 13, 2010 8:28 am
Full Name: Sebastian Kayser

Re: Working with cmdlets, calling them from a Windows task

Post by skayser »

Sure, SR number is #5129711
Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests