Working with cmdlets, calling them from a Windows task

PowerShell script exchange

Working with cmdlets, calling them from a Windows task

Veeam Logoby skayser » Thu Apr 21, 2011 10:03 am

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
skayser
Enthusiast
 
Posts: 27
Liked: never
Joined: Tue Jul 13, 2010 8:28 am
Full Name: Sebastian Kayser

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

Veeam Logoby Vitaliy S. » Thu Apr 21, 2011 10:08 am

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
Vitaliy S.
Veeam Software
 
Posts: 19539
Liked: 1097 times
Joined: Mon Mar 30, 2009 9:13 am
Full Name: Vitaliy Safarov

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

Veeam Logoby skayser » Thu Apr 21, 2011 10:23 am

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.
skayser
Enthusiast
 
Posts: 27
Liked: never
Joined: Tue Jul 13, 2010 8:28 am
Full Name: Sebastian Kayser

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

Veeam Logoby Vitaliy S. » Thu Apr 21, 2011 12:38 pm

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?
Vitaliy S.
Veeam Software
 
Posts: 19539
Liked: 1097 times
Joined: Mon Mar 30, 2009 9:13 am
Full Name: Vitaliy Safarov

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

Veeam Logoby skayser » Thu Apr 21, 2011 2:37 pm

Sure, SR number is #5129711
skayser
Enthusiast
 
Posts: 27
Liked: never
Joined: Tue Jul 13, 2010 8:28 am
Full Name: Sebastian Kayser


Return to PowerShell



Who is online

Users browsing this forum: Yahoo [Bot] and 3 guests