PowerShell script exchange
fgw
Enthusiast
Posts: 83
Liked: 2 times
Joined: Jun 11, 2009 8:39 pm
Full Name: Franz Glatzer
Contact:

powershell cmdlets

Post by fgw »

currently looking into powershell extensions:

trying to create a script to add a job, change jobparameters and add vm's to this job. the first point where i failed was the unfortunate formatting in the userguide. eg. the description for compression level:

Compression-
Level
Specify a compression level - from 0 to 9

where "-" is to interpret as a linebreak and not part of the option name, thus optionname is CompressionLevel and not Compression-Level as i used first.

a bit more tricky seems to be the specification of job schedule time in Set-VBRJobSchedule:
i'm not able to find out how to specify to run the job daily at a defined time. documentation is poor at least:

what is ScheduleOptions+PeriodicallyOptions in OptionsDaily? do i have to use this at all, or should i use StartDateTime instead and how?

Code: Select all

Syntax
Set-VBRJobSchedule [Job <CDBJob>] [EndDateTime <DateTime>][EndDateTimeSpecified 
<Boolean>] [LatestRun <DateTime>] [OptionsDaily <ScheduleOptions+DailyOptions>] [OptionsPeri-
odically <ScheduleOptions+PeriodicallyOptions>] [RepeatNumber <Int32>] [RepeatSpecified 
<Boolean>] [RepeatTimeUnit <String>] [RepeatTimeUnitMs <Int32>] [RetrySpecified <Boolean>] 
[RetryTimeout <Int32>] [RetryTimes <Int32>] [StartDateTime <DateTime>]
LatestRun Date and time of day of the latest backup run
OptionsDaily Scheduling options for running a backup job daily at a specific time
OptionsPeriodically Scheduling options for running a backup job daily periodically at a specific interval
RepeatNumber Number of times for which a job should be repeated
RepeatSpecified Set this parameter to TRUE if you want to run a backup job daily periodically at a specific interval
RepeatTimeUnit Units of time for running a backup job daily periodically at a specific interval (hours or minutes)
RepeatTimeUnitMs Number of hours or minutes in which a job should be repeatedly run
RetrySpecified Set this parameter to TRUE if you want to re-run the job run in case it fails
RetryTimeout Timeout (in minutes) before the job should be re-run in case it fails
RetryTimes Number of attempts for which the job should be re-run if it fails. To re-run the job, set the RetrySpecified parameter to TRUE
StartDateTime Date and time of day when a backup should be started

expect some more questions popping up ...

Vitaliy S.
Product Manager
Posts: 24354
Liked: 1897 times
Joined: Mar 30, 2009 9:13 am
Full Name: Vitaliy Safarov
Contact:

Re: powershell cmdlets

Post by Vitaliy S. »

Hello Franz,

Thank you for pointing out the documentation typo for compression levels! At least we know that someone reads all the manuals :D

As for how to use Set-VBRJobSchedule properly, actually there are two ways to achieve what you're willing for:

1. You may look at the job properties using GUI and set the same parameters for your PS job script. Here is an example for one of my jobs:

Code: Select all

$job = Get-VBRJob “jobName”
Set-VBRJobOptions ($job) -EmailNotification $true 
Set-VBRJobOptions ($job) -RetainCycles 2
Set-VBRJobOptions ($job) -CompressionLevel 4

$vo = $job.GetVssOptions()
$vo.Credentials = [Veeam.Backup.Common.CCredentials]::CreateEmpty()
$vo.Credentials.UserName = "eu\tforest"
$vo.Credentials.Password= "xxxxx"
$vo.Enabled = $true
$job.SetVssOptions($vo)
$job.Save()
If you'd like to get all options available, you should use the following command - object | gm

Example:

Code: Select all

$job | gm
$job.GetVssOptions() | gm
2. Another way is to use Windows Scheduler:

You should create a PS script (runjob.ps1) at first:

Code: Select all

Add-PSSnapin VeeamPSSnapIn
Start-VBRJob “jobName”
Then execute this script using Windows Scheduler:

Code: Select all

powershell.exe runjob.ps1
Hope it helps! Thank you!

fgw
Enthusiast
Posts: 83
Liked: 2 times
Joined: Jun 11, 2009 8:39 pm
Full Name: Franz Glatzer
Contact:

Re: powershell cmdlets

Post by fgw »

... and it gets even more frustrating! was anybody able to use powershell integration successfully?

missing documentation and mistakes in the userguide makes it impossible for me to use this stuff ...

the cmdlet is called Get-VBRJob while examples list it as Get-Job?

anyway, look at this:

while

Code: Select all

Get-VBRJobOptions (Get-VBRJob Job1)
and

Code: Select all

Set-VBRJobOptions (Get-VBRJob Job1) -CompressionLevel 9
are working as expected, adding "-EmailNotification $true" fails:

Code: Select all

Set-VBRJobOptions (Get-VBRJob Job1) -CompressionLevel 9 -EmailNotification $true
Set-VBRJobOptions : Parameter set cannot be resolved using the specified named
parameters.
At line:1 char:18
+ Set-VBRJobOptions  <<<< (Get-VBRJob Job1) -CompressionLevel 9 -EmailNotificat
ion $true
changing -EmailNotification $true to True or true or 1 has no effect ...

although changing VSS paramters should work, but fails also, i'm still unable to find a way to specifiy advanced VSS settings like individual username/password for different vm's within a job!

fgw
Enthusiast
Posts: 83
Liked: 2 times
Joined: Jun 11, 2009 8:39 pm
Full Name: Franz Glatzer
Contact:

Re: powershell cmdlets

Post by fgw »

thanks vitaliy,

i'm a step further now!

looks like there can be used only one option at a time:

while

Code: Select all

Set-VBRJobOptions (Get-VBRJob Job1) -CompressionLevel 9 -EmailNotification $true
fails, splittin gthis up into two seperate calls to Set-VBRJobOptions succeeds:

Code: Select all

Set-VBRJobOptions (Get-VBRJob Job1) -CompressionLevel 9 
Set-VBRJobOptions (Get-VBRJob Job1) -EmailNotification $true
is this the way to use the cmdlets? do i have to supply just a single option at a time? on the other haand, adding a job allows me to specify all parameters on a single line?

Gostev
SVP, Product Management
Posts: 26917
Liked: 4373 times
Joined: Jan 01, 2006 1:01 am
Location: Baar, Switzerland
Contact:

Re: powershell cmdlets

Post by Gostev »

Franz, did you read Vitaly's post above on how to set job options?

Answering your question, yes we have a number of customers using PowerShell integration successfully. One customer has built complete automated backup recoverability verification test system based on our PowerShell - he is going to blog about this soon and share his code (not sure if his blog will be in English though) :)

P.S. Oh, you beat me with your new post :)

Gostev
SVP, Product Management
Posts: 26917
Liked: 4373 times
Joined: Jan 01, 2006 1:01 am
Location: Baar, Switzerland
Contact:

Re: powershell cmdlets

Post by Gostev »

Actually it appears that this customer already posted this on his blog, but it is in Russian:
http://goodserg-it.blogspot.com/2010/04 ... ackup.html

Still, you can download and check out the actual PowerShell scripts (very impressive btw).

Also, you can use Google Translate, it does decent job:
http://translate.google.com/translate?h ... pot.com%2F

fgw
Enthusiast
Posts: 83
Liked: 2 times
Joined: Jun 11, 2009 8:39 pm
Full Name: Franz Glatzer
Contact:

Re: powershell cmdlets

Post by fgw »

ok, i give up on this!

for now i have three issues:

[1]
how to specify vm (ore more as only one) in Add-VBRBackupJob -options vm1, vm2

i get the error:

Add-VBRBackupJob Job2 VDDK san "My Computer" "H:\" Job1name -Objects Test7
Add-VBRBackupJob : Web Service credentials are not set for the host "vcserver"
At line:1 char:17
+ Add-VBRBackupJob <<<< Job2 VDDK san "My Computer" "H:\" Job1name -Objects Te
st7


[2]
how to specify a schedule time to run a job daily at a certain time in Set-VBRJobSchedule?

[3]
how to specifiy different VSS user/password pairs for different vm's within a single job?

vitaliy or anton if you pls can answer this questions i will can contiue ...

ps. although i'm new to powershell and might be asking some silly questions, i still think the documentation is missing some essential parts thus holding me back. hey, i'm able to program win32 api in c++, so powershell and veeam cmdlets should be a problem i'm able to solve.

fgw
Enthusiast
Posts: 83
Liked: 2 times
Joined: Jun 11, 2009 8:39 pm
Full Name: Franz Glatzer
Contact:

Re: powershell cmdlets

Post by fgw »

anton, this turns out to be funny!

when you stated a customer is already putting this info together, but its not in english, i refused to note: hopefully its not russian! :mrgreen:

anyway, downloading ...

fgw
Enthusiast
Posts: 83
Liked: 2 times
Joined: Jun 11, 2009 8:39 pm
Full Name: Franz Glatzer
Contact:

Re: powershell cmdlets

Post by fgw »

finally i'm coming to the conclusion powershell integration like it is now is more or less useless!

some cmdlets are simply not working as documented!
some of them are not working at all!

perhaps it would be a nice feature, but not in the state it is right now.

anton, from looking at the script of the user you posted above, his sripts are using just three different cmdlets:
Set-VBRRestoreVM
Get-VBRJobDestination
Get-VBRJobRestorePoints

but there is still no way to successfully add a job, add vm's to an existing job, change VSS parameters on a per vm basis, ...
well, i managed to add a job, but this job did not have a single vm and adding a vm to this job fails also.

i played around with it for just about 3 hours and ran into several different issues with not working cmdlets. interesing to see what happens if somebody looks into this a bit deeper ...

i'm done with powershell integration until veeam is reworking the documentation AND fixing this bugs. hopefully v5 will come with a useable integration ...

sorry for saying this, but thats the way it is!

Gostev
SVP, Product Management
Posts: 26917
Liked: 4373 times
Joined: Jan 01, 2006 1:01 am
Location: Baar, Switzerland
Contact:

Re: powershell cmdlets

Post by Gostev »

Franz, I am sorry you could not make this work for you after spending 3 hours, but your conclusion about our PowerShell capabilities are definitely far from reality.

I can assure you cmdlets we have are working as advertized, because we are using them daily for testing automation. Each new product build passes extensive automated tests which leverage these cmdlets to create and configure new jobs, run them, restore, etc. All the test are based on the very same PowerShell cmdlets.

I also know of many customers and partners, who have developed various applications based on our PowerShell, for example one partner has developed a script that creates multiple Veeam Backup jobs automatically (to help him with faster deployment of Veeam Backup in the customer environments).

Of course, as any scripting this is not so straight-forward, which is why I know many customers are choosing to hire consultants to implement custom scripts based on our PowerShell extension.

Neither me nor Vitaly are developers, so we don't know PowerShell and don't create scripts using our cmdlets ourselves, thus unfortunately we cannot help with this efficiently or guide you throught the creation of script you want to create on this forum (we have to engage development for any question) . But if you'd like, please give me an example of cmdlet that you believe "is not working at all", and I will ask the corresponging developer to provide working example - just to prove the issue is not with cmdlets, but with the incorrect syntax or usage.

Thanks!

Vitaliy S.
Product Manager
Posts: 24354
Liked: 1897 times
Joined: Mar 30, 2009 9:13 am
Full Name: Vitaliy Safarov
Contact:

Re: powershell cmdlets

Post by Vitaliy S. »

Franz,

Thank you for your feedback.

As for the setting up the job to run on the certain time, the syntax should look like the following:

Code: Select all

$job = Get-VBRJob “JobName”
Setting up the job to run on daily basis:

Code: Select all

$s = $job.GetScheduleOptions()
$s.OptionsDaily.Enabled = $true
$s.OptionsDaily.Time = "12:58:53"
$job.SetScheduleOptions($s)
Allowing the job to run automatically:

Code: Select all

$opt= $job.GetOptions()
$opt.RunManually = $false
$job.SetOptions($opt)
$job.Save()
Unfortunately, you cannot add VMs to an existing job you can only replace the existing VMs, for example: you've got the Job with VM1, VM2. You may replace VMs that are added to the job by executing this command:

Code: Select all

Set-VBRBackupJob "Backup Job 2" -object VM1, VM5
So after executing you'll have VM1, VM5 within the job, but VM2 will be removed.

Changing VSS parameters per VM is not currently available in the product as a feature (it is coming with v5), right now you can only change it for the whole job.

Thank you!

fgw
Enthusiast
Posts: 83
Liked: 2 times
Joined: Jun 11, 2009 8:39 pm
Full Name: Franz Glatzer
Contact:

Re: powershell cmdlets

Post by fgw »

anton, vitaliy THANKS for your assistance!

ok, let me give you an example:

from looking at the documentation of Add-VBRBackupJob:

Code: Select all

Syntax:
Add-VBRBackupJob [Name <String>] [Type <String>] [Mode <String>] [Host <String>] [Folder <String>] [Filename <String>] [Objects <String[]>]

Example:
Add-VBRBackupJob jobName VDDK "san;nbd" "My Computer" 
"C:\VmBackups" "job2" -Objects knt2
so assuming the following command should work:

Code: Select all

Add-VBRBackupJob Job1 VDDK san "My Computer" "H:\" Job1name -Objects Test7
this results in adding a job named Job1 without any vm!

so lets try to add a VM:

again form the manual:

Code: Select all

Syntax:
Set-VBRBackupJob [Name <String>] [Type <String>] [Mode <String>] [Objects <String>]

where all parameters besides Name are optional
so here is the command i used:

Code: Select all

Set-VBRBackupJob (Get-VBRJob Job1) -Objects VEXRHL
this results in the following:
Set-VBRBackupJob : Job not found...
At line:1 char:17
+ Set-VBRBackupJob <<<< (Get-VBRJob Job1) -Objects VEXRHL


the job "Job1" can still be seen in "Veeam Backup and FastSCP" but still contains no vm.

the funny thing here is, if i add a vm in the gui first, the above command prints the same error, removes the vm i previously added in the gui but does not add the vm specified in the command. so this makes me assume the command somehow manages to find the job although the error says differently.

ok, looking at the error i got above, may be the job name was not found somehow. lets try another command:

Code: Select all

PS C:\Documents and Settings\adm.glatzer\Desktop> Get-VBRJobOptions (Get-VBRJob Job1)
this prints out a list of jobparameters for "Job1".

anton, tell me what's wrong here. i just used the documentation and the examples supplied there!

vitaliy, with your examples i'm able to set the job to run daily at acertain time.

unfortunately, i'm still unable to add vm's to the job.

ok, for changing advanced vss parameters i will have to wait for v5.


once again, anton and vitaliy: THANKS for your help!

although there are consultants out there, i guess a customer should be able to do such a simple task as adding a job at his own, given software behaves as ducumented!

Gostev
SVP, Product Management
Posts: 26917
Liked: 4373 times
Joined: Jan 01, 2006 1:01 am
Location: Baar, Switzerland
Contact:

Re: powershell cmdlets

Post by Gostev »

OK, we will check with devs on possible reasons why specified VMs may not get added to the job.

Vitaliy S.
Product Manager
Posts: 24354
Liked: 1897 times
Joined: Mar 30, 2009 9:13 am
Full Name: Vitaliy Safarov
Contact:

Re: powershell cmdlets

Post by Vitaliy S. »

Franz,

I've just checked your issue with the development team, please use this command to replace VMs:

Code: Select all

Set-VBRBackupJob "Job1" -object VEXRHL
Should work!

Vitaliy S.
Product Manager
Posts: 24354
Liked: 1897 times
Joined: Mar 30, 2009 9:13 am
Full Name: Vitaliy Safarov
Contact:

Re: powershell cmdlets

Post by Vitaliy S. »

Also could you please check that Test7 is spelled properly (upper/lower case), try usuing quotes for this object and see whether it solves your issue or not:

Code: Select all

Add-VBRBackupJob Job1 VDDK san "My Computer" "H:\" Job1name -Objects "Test7"

fgw
Enthusiast
Posts: 83
Liked: 2 times
Joined: Jun 11, 2009 8:39 pm
Full Name: Franz Glatzer
Contact:

Re: powershell cmdlets

Post by fgw »

vitaliy, already tried this before here are results:

creating a new job with the following command returns this error

Add-VBRBackupJob Job1 VDDK san "My Computer" "H:\" Job1name -Objects "Test7"
Add-VBRBackupJob : Web Service credentials are not set for the host "VCserver"
At line:1 char:17
+ Add-VBRBackupJob <<<< Job1 VDDK san "My Computer" "H:\" Job1name -Objects "Test7"


the job is created, BUT has no vm associated with it. no matter if i use Test7 or "Test7".

the interesting part follows:

if i go ahead and add a vm e.g. Test7 to this job in the gui, and run the following command to remove Test7 and add VEXRHL instead, i receive the same errormessage

Set-VBRBackupJob "Job1" -object VEXRHL
Set-VBRBackupJob : Web Service credentials are not set for the host "VCserver"
At line:1 char:17
+ Set-VBRBackupJob <<<< "Job1" -object VEXRHL


this results in the original vm Test7 removed from the job BUT the vm named VEXRHL does not get added to the job, leaving an empty job!

may be the cmdlets which are run on the backup server needs to communicate with VCserver in order to validate if the vm to be added exists and this communication fails for any reason. all this is done with an administrator account which should have sufficient privs.
is there a certain port which needs to be opened for this communication?

any idea what the errormessage Web Service credentials are not set for the host "VCserver" is telling us?

Gostev
SVP, Product Management
Posts: 26917
Liked: 4373 times
Joined: Jan 01, 2006 1:01 am
Location: Baar, Switzerland
Contact:

Re: powershell cmdlets

Post by Gostev »

Franz, can you please send all logs from Help | Support information to support@veeam.com, as we could not reproduce the web service credentials issue easily and would like to inverstigate your specific situation more closely.

Achim.Z.
Novice
Posts: 9
Liked: never
Joined: Aug 09, 2010 6:42 am
Contact:

Re: powershell cmdlets

Post by Achim.Z. »

Hi there;

i got a quastion about that part of the code:

Code: Select all

$s = $job.GetScheduleOptions()
$s.OptionsDaily.Enabled = $true
$s.OptionsDaily.Time = "12:58:53"
$job.SetScheduleOptions($s)
The job should be set to run on that time once a day.
In my case it is set to run periodically every hour.
Did i do a mistake?

regards
Achim.Z.

Vitaliy S.
Product Manager
Posts: 24354
Liked: 1897 times
Joined: Mar 30, 2009 9:13 am
Full Name: Vitaliy Safarov
Contact:

Re: powershell cmdlets

Post by Vitaliy S. »

Achim,

Let me check this with our PowerShell guru for you, I will post a reply as soon as I get any information from him.

Vitaliy S.
Product Manager
Posts: 24354
Liked: 1897 times
Joined: Mar 30, 2009 9:13 am
Full Name: Vitaliy Safarov
Contact:

Re: powershell cmdlets

Post by Vitaliy S. »

Achim, here is the example of running backup/replication job every hour:

Code: Select all

$job = get-vbrjob "JobName"

$sch = $job.getScheduleOptions()
$sch.OptionsPeriodically.Enabled = $true
$sch.OptionsPeriodically.FullPeriod = 60
$job.SetScheduleOptions($sch)

$opt = $job.GetOptions()
$opt.RunManually = $false
$job.SetOptions($opt)

$job.Save()
Hope this helps!

Achim.Z.
Novice
Posts: 9
Liked: never
Joined: Aug 09, 2010 6:42 am
Contact:

Re: powershell cmdlets

Post by Achim.Z. »

Hi;

sorry, that the answer took a little;
yes and no: yes, the job can be added, no it is not really what i needed :-(
I need to add the OptionsDaily for a Backup ata special time, eg 22:23h

the point is, if i use:

Code: Select all

$sch = $job.getScheduleOptions()
$sch.OptionsDaily.Enabled = $true
$sch.OptionsDaily.Time = "12:58"
$job.SetScheduleOptions($sch)
the time is set now, but active is still "Periodically every" and not "run at"

Regards
Achim

Vitaliy S.
Product Manager
Posts: 24354
Liked: 1897 times
Joined: Mar 30, 2009 9:13 am
Full Name: Vitaliy Safarov
Contact:

Re: powershell cmdlets

Post by Vitaliy S. »

Achim,

Please try to use the example below, it should be exactly what you're looking for:

Code: Select all

$job.SetOptions($opt)
$sch = $job.getScheduleOptions()
$sch.OptionsDaily.Enabled = $true
$sch.OptionsDaily.Enabled
$sch.OptionsPeriodically.Enabled = $false
$sch.OptionsDaily.Time = "14:00:00"
$job.SetScheduleOptions($sch)
$job.Save()
Thank you!

Achim.Z.
Novice
Posts: 9
Liked: never
Joined: Aug 09, 2010 6:42 am
Contact:

Re: powershell cmdlets

Post by Achim.Z. »

Hey, that's funny;

I lost all the jobs, trying to modify with that ... *hahaha*

Code: Select all

$job = get-vbrjob "ServerName"
$job.SetOptions($opt)
$sch = $job.getScheduleOptions()
$sch.OptionsDaily.Enabled = $true
$sch.OptionsDaily.Enabled
$sch.OptionsPeriodically.Enabled = $false
$sch.OptionsDaily.Time = "14:00:00"
$job.SetScheduleOptions($sch)
$job.Save()
regards
Achim

Vitaliy S.
Product Manager
Posts: 24354
Liked: 1897 times
Joined: Mar 30, 2009 9:13 am
Full Name: Vitaliy Safarov
Contact:

Re: powershell cmdlets

Post by Vitaliy S. »

Sorry to hear that, I've just posted an example from the lab of mine, if you are able to reproduce this issue, please contact our technical support team for assistance directly.

Achim.Z.
Novice
Posts: 9
Liked: never
Joined: Aug 09, 2010 6:42 am
Contact:

Re: powershell cmdlets

Post by Achim.Z. »

Hi;

I think i have to correct my statement.
The jobs are not gone, they are no longer visable in the gui!

regards
achim

Vitaliy S.
Product Manager
Posts: 24354
Liked: 1897 times
Joined: Mar 30, 2009 9:13 am
Full Name: Vitaliy Safarov
Contact:

Re: powershell cmdlets

Post by Vitaliy S. »

Achim, I haven't heard these issues reported before, so please log a support ticket with our technical team for troubleshooting steps.

pavan.penmetsa
Lurker
Posts: 1
Liked: never
Joined: Feb 24, 2011 1:34 pm
Full Name: pavan penmetsa
Contact:

Re: powershell cmdlets

Post by pavan.penmetsa »

Hello,
I am working on Surebackup script. Can anyone let me know what we need to pass to the following commandlet as argument.

get-VSBTaskSession -session "?"

Please give me a clear example.

Thanks,
Pavan

flavor4real
Expert
Posts: 205
Liked: 5 times
Joined: Nov 22, 2010 7:57 pm
Full Name: DS
Contact:

Re: powershell cmdlets

Post by flavor4real »

Hello,
I'm reading through here and it's interesting. I don't know much about PowerShell cmdlt and I used the

>> Start-VBRJob Job1

but it didn't worked. the modarators helped me out and pointed me to the right directions and I found out that I have to write it like this:
>> Get-VBRJob | where {$_.Name –eq “JobName1”} | Start-VBRJob

I gave it a shot and it works for me. I'm planning to schedule a backup sequence for several overlapping jobs. Thanks for the help guys!
////////////////////////////
I found that the Cmdlet Set-VBRBackupJob is not listed under the available commands, which you can call up with Get-VBRCommand. I see, Set-VBRJobObject listed....

Alexey D.

Re: powershell cmdlets

Post by Alexey D. »

I will ask devs and will post back.

Vitaliy S.
Product Manager
Posts: 24354
Liked: 1897 times
Joined: Mar 30, 2009 9:13 am
Full Name: Vitaliy Safarov
Contact:

Re: powershell cmdlets

Post by Vitaliy S. »

flavor4real wrote:I found that the Cmdlet Set-VBRBackupJob is not listed under the available commands, which you can call up with Get-VBRCommand. I see, Set-VBRJobObject listed....

And what's the question? Have you been successfull in scheduling your jobs? What would you like to accomplish next?

Regarding Set-VBRJobObjects, here is one of the usage examples for this cmdlet: set-vbrjobobject add VC folders

Post Reply

Who is online

Users browsing this forum: No registered users and 9 guests