powershell cmdlets

PowerShell script exchange

powershell cmdlets

Veeam Logoby fgw » Thu Apr 08, 2010 10:09 am

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 ...
fgw
Enthusiast
 
Posts: 65
Liked: 2 times
Joined: Thu Jun 11, 2009 8:39 pm
Full Name: Franz Glatzer

Re: powershell cmdlets

Veeam Logoby Vitaliy S. » Thu Apr 08, 2010 12:53 pm

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

Re: powershell cmdlets

Veeam Logoby fgw » Thu Apr 08, 2010 12:59 pm

... 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: 65
Liked: 2 times
Joined: Thu Jun 11, 2009 8:39 pm
Full Name: Franz Glatzer

Re: powershell cmdlets

Veeam Logoby fgw » Thu Apr 08, 2010 1:07 pm

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?
fgw
Enthusiast
 
Posts: 65
Liked: 2 times
Joined: Thu Jun 11, 2009 8:39 pm
Full Name: Franz Glatzer

Re: powershell cmdlets

Veeam Logoby Gostev » Thu Apr 08, 2010 1:08 pm

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
Veeam Software
 
Posts: 21396
Liked: 2349 times
Joined: Sun Jan 01, 2006 1:01 am
Location: Baar, Switzerland

Re: powershell cmdlets

Veeam Logoby Gostev » Thu Apr 08, 2010 1:16 pm

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
Gostev
Veeam Software
 
Posts: 21396
Liked: 2349 times
Joined: Sun Jan 01, 2006 1:01 am
Location: Baar, Switzerland

Re: powershell cmdlets

Veeam Logoby fgw » Thu Apr 08, 2010 1:26 pm

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: 65
Liked: 2 times
Joined: Thu Jun 11, 2009 8:39 pm
Full Name: Franz Glatzer

Re: powershell cmdlets

Veeam Logoby fgw » Thu Apr 08, 2010 1:29 pm

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: 65
Liked: 2 times
Joined: Thu Jun 11, 2009 8:39 pm
Full Name: Franz Glatzer

Re: powershell cmdlets

Veeam Logoby fgw » Thu Apr 08, 2010 3:02 pm

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!
fgw
Enthusiast
 
Posts: 65
Liked: 2 times
Joined: Thu Jun 11, 2009 8:39 pm
Full Name: Franz Glatzer

Re: powershell cmdlets

Veeam Logoby Gostev » Thu Apr 08, 2010 4:04 pm

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!
Gostev
Veeam Software
 
Posts: 21396
Liked: 2349 times
Joined: Sun Jan 01, 2006 1:01 am
Location: Baar, Switzerland

Re: powershell cmdlets

Veeam Logoby Vitaliy S. » Thu Apr 08, 2010 4:07 pm

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

Re: powershell cmdlets

Veeam Logoby fgw » Thu Apr 08, 2010 5:03 pm

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!
fgw
Enthusiast
 
Posts: 65
Liked: 2 times
Joined: Thu Jun 11, 2009 8:39 pm
Full Name: Franz Glatzer

Re: powershell cmdlets

Veeam Logoby Gostev » Thu Apr 08, 2010 6:49 pm

OK, we will check with devs on possible reasons why specified VMs may not get added to the job.
Gostev
Veeam Software
 
Posts: 21396
Liked: 2349 times
Joined: Sun Jan 01, 2006 1:01 am
Location: Baar, Switzerland

Re: powershell cmdlets

Veeam Logoby Vitaliy S. » Fri Apr 09, 2010 8:48 am

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

Re: powershell cmdlets

Veeam Logoby Vitaliy S. » Fri Apr 09, 2010 9:22 am

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

Next

Return to PowerShell



Who is online

Users browsing this forum: No registered users and 2 guests