-
- Veteran
- Posts: 282
- Liked: 26 times
- Joined: Nov 10, 2010 6:51 pm
- Full Name: Seth Bartlett
- Contact:
Re: PowerShell - Get-VbrJob
I was also happy to see a dedicated powershell forum. I use to search for the word "powershell" daily
Skype: Sethbartlett88 - Make sure to label who you are and why you want to add me
Twitter: @sethbartlett
If my post was helpful, please like it. Sometimes twitter is quicker to hit me up if you need me.
Twitter: @sethbartlett
If my post was helpful, please like it. Sometimes twitter is quicker to hit me up if you need me.
Re: PowerShell - Get-VbrJob
<-- PowerShell addict! Can't say I blame you though - I really enjoy writing scripts and learning with PS.Sethbartlett wrote:I was also happy to see a dedicated powershell forum. I use to search for the word "powershell" daily
-
- Novice
- Posts: 4
- Liked: never
- Joined: Nov 23, 2011 4:05 pm
- Full Name: Marcin Frycz
- Location: London, UK
- Contact:
Re: PowerShell - Get-VbrJob
Thanks a lot Shogan
hope this wont be much of a trouble to make this adjustments...
Also i am looking at this script myself (and if i will figure out something i definitelly post all discoveries)
hope this wont be much of a trouble to make this adjustments...
Also i am looking at this script myself (and if i will figure out something i definitelly post all discoveries)
Re: PowerShell - Get-VbrJob
Hi Marcin,mfrycz wrote:Hi guys,
this is really good piece of code
i am new to ps and trying to amend it slightly:
1. can it report insted of per-job details from per-vm details ?
2. can it specify just particular "*name*" or it have to be across all backups
3. i have several veeam servers, can i quote all of them ?
4. can we add size of the backup ?
thanks again for all your help.
So I passed my VCP5 exam the other day, meaning I finally have a bit of time to catch up on other things going on outside of work! Anyway, I decided to have a quick look at your questions, and think I can answer some of them...
1. can it report instead of per-job details, per-VM details?
Well, I didn't have too much time to look into this, but I have a quick way to get the list of VMs in each Backup Job. Use the following:
Code: Select all
$Backups = Get-VBRBackup
foreach ($Backup in $Backups) {
$Backup.Name
Write-Host "--------------------------"
$Backup.GetObjects() | Select Name
Write-Host "--------------------------"
}
2. can it specify just particular "*name*" or it have to be across all backups
Yes - this is easy to change in the script - just change the line near the top of the script that reads:
Code: Select all
$Jobs = Get-VBRJob | ?{$_.Name -match ""}
Code: Select all
$Jobs = Get-VBRJob | ?{$_.Name -match "yourbackupname"}
3. As I mentioned before, remoting may be a way of doing this - I currently don't have more than one Veeam server to test with, nor the time unfortunately - have a read up on PowerShell remoting / WinRM and perhaps you can find a way to modify the script to do this? Otherwise, my only other suggestion would be to run the script on each server and combine results.
4. Yes, I'm sure this is possible. In the Veeam v6 cmdlets, Get-VBRBackupSession returns all Backup Sessions and part of the info you can get out of each object returned is DataSize - which should be what you are looking for. I'll try this out in my script tomorrow and see if I can add a column for this, otherwise feel free to try yourself. Currently I have upgraded to v6 in my home lab and this script is for v5 so I can't test the v5 version with "DataSize" for you now. I'll have to wait till tomorrow when I am back at work / on lunch. But for v6 at home, I have confirmed this property is available.
e.g.
Code: Select all
$sessions = Get-VBRBackupSession
foreach ($sess in $sessions) { $sess.BackupStats }
Anyway, I'll try see what else I can do for your 4th query on DataSize and the script tomorrow. Hope that helps
For all others - this script doesn't work in Veeam B&R v6 in its current state (only for v5.x), however, I have updated it to work for v6 - well I have made another "V6" version - I'll upload it and post a link at some point tomorrow!
-
- Veteran
- Posts: 293
- Liked: 19 times
- Joined: Apr 13, 2011 12:45 pm
- Full Name: Thomas McConnell
- Contact:
Re: PowerShell - Get-VbrJob
On v6 there where some changes for the better to get this info
Code: Select all
[vPowerCLI] C:\> $sess = (Get-VBRBackupSession | Sort CreationTime -Descending)[0]
[vPowerCLI] C:\> $sess.BackupStats
BackupSize DataSize DedupRatio CompressRatio
---------- -------- ---------- -------------
700036096 1583142727 100 44
[vPowerCLI] C:\> $sess.GetTaskSessions()[0]
[vPowerCLI] C:\> $sess.GetTaskSessions()[0].progress
TotalObjects : 5
ProcessedObjects : 5
TotalSize : 147035105280
ProcessedSize : 147035105280
ProcessedUsedSize : 74007285430
Progress : 0
StartTime : 18/01/2012 12:05:09
StopTime : 18/01/2012 12:06:37
AvgSpeed : 842022280
ReadSize : 562036736
StoredSize : 132517347
Bottleneck : NotDefined
SourceStorage : 0
SourceProxy : 0
SourceNetwork : 0
TargetStorage : 0
TargetProxy : 0
TargetNetwork : 0
Duration : 00:01:27.8940000
DisplayName : 100% completed
_sourceStorage : 0
_sourceProxy : 0
_sourceNetwork : 0
_targetStorage : 0
_targetProxy : 0
_targetNetwork : 0
Re: PowerShell - Get-VbrJob
Thanks Thomas - I noticed the BackupStats seems new - couldn't find that in an install of v5 I have.ThomasMc wrote:On v6 there where some changes for the better to get this info
Code: Select all
[vPowerCLI] C:\> $sess = (Get-VBRBackupSession | Sort CreationTime -Descending)[0] [vPowerCLI] C:\> $sess.BackupStats BackupSize DataSize DedupRatio CompressRatio ---------- -------- ---------- ------------- 700036096 1583142727 100 44 [vPowerCLI] C:\> $sess.GetTaskSessions()[0] [vPowerCLI] C:\> $sess.GetTaskSessions()[0].progress TotalObjects : 5 ProcessedObjects : 5 TotalSize : 147035105280 ProcessedSize : 147035105280 ProcessedUsedSize : 74007285430 Progress : 0 StartTime : 18/01/2012 12:05:09 StopTime : 18/01/2012 12:06:37 AvgSpeed : 842022280 ReadSize : 562036736 StoredSize : 132517347 Bottleneck : NotDefined SourceStorage : 0 SourceProxy : 0 SourceNetwork : 0 TargetStorage : 0 TargetProxy : 0 TargetNetwork : 0 Duration : 00:01:27.8940000 DisplayName : 100% completed _sourceStorage : 0 _sourceProxy : 0 _sourceNetwork : 0 _targetStorage : 0 _targetProxy : 0 _targetNetwork : 0
Also, Marcin, for you - see above in Thomas' post, I think this is the property would be looking for in answer to one of your questions:
StoredSize : 132517347
Re: PowerShell - Get-VbrJob
v6 of the reporting script is up for those of you running Veeam B&R v6 - I have placed a download link on my original blog post - http://www.shogan.co.uk/?p=871
The only difference is that v6 PowerShell now returns information about the backup sessions in properties for each backup session object, not nested in the .Info. section. So instead of $_.Info.CreationTime, it would just be $_.CreationTime now for example
The only difference is that v6 PowerShell now returns information about the backup sessions in properties for each backup session object, not nested in the .Info. section. So instead of $_.Info.CreationTime, it would just be $_.CreationTime now for example
-
- VP, Product Management
- Posts: 7076
- Liked: 1510 times
- Joined: May 04, 2011 8:36 am
- Full Name: Andreas Neufert
- Location: Germany
- Contact:
Re: PowerShell - Get-VbrJob
Hello
Shogan thanks for this outstanding script.
I extended your code because of a customer request in 2 ways:
1. Load VeeamPSSnapin
2. Add VMList to the table This is based on Shogans idea from his post 17 Jan 2012, 23:19
But be carefull the VMlist only reference to the actual include list of the job. So if you add or delete VMs in Jobs every table entry from the job changes.
Does anyone knows how to fix that.
Shogan thanks for this outstanding script.
I extended your code because of a customer request in 2 ways:
1. Load VeeamPSSnapin
2. Add VMList to the table This is based on Shogans idea from his post 17 Jan 2012, 23:19
But be carefull the VMlist only reference to the actual include list of the job. So if you add or delete VMs in Jobs every table entry from the job changes.
Does anyone knows how to fix that.
Code: Select all
#load Veeam Powershell Snapin
Add-PSSnapin -Name VeeamPSSnapIn -ErrorAction SilentlyContinue
#Style
$style = @"
<style>
TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}
TH{border-width: 1px;padding: 2px;border-style: solid;border-color: black;background-color:orange}
TD{border-width: 1px;padding: 2px;border-style: solid;border-color: black;background-color:lightblue}
tr.special {background: #000080;} <tr class="special"></tr>
</style>
"@
$Report = @()
$Jobs = Get-VBRJob | ?{$_.Name -match ""}
foreach ($job in $Jobs) {
$jobName = $job.Name
$table = New-Object system.Data.DataTable "$table01"
#region Setup table columns
$col1 = New-Object system.Data.DataColumn Index,([int])
$col2 = New-Object system.Data.DataColumn JobName,([string])
$col3 = New-Object system.Data.DataColumn VMList,([String])
$col4 = New-Object system.Data.DataColumn StartTime,([DateTime])
$col5 = New-Object system.Data.DataColumn StopTime,([DateTime])
$col6 = New-Object system.Data.DataColumn FileName,([string])
$col7 = New-Object system.Data.DataColumn CreationTime,([DateTime])
$col8 = New-Object system.Data.DataColumn AvgSpeedMB,([int])
$col9 = New-Object system.Data.DataColumn Duration,([TimeSpan])
$col10 = New-Object system.Data.DataColumn Result,([String])
$table.columns.add($col1)
$table.columns.add($col2)
$table.columns.add($col3)
$table.columns.add($col4)
$table.columns.add($col5)
$table.columns.add($col6)
$table.columns.add($col7)
$table.columns.add($col8)
$table.columns.add($col9)
$table.columns.add($col10)
#endregion
#Grab all Backup Sessions on the server where their .JobId property is the same as the Get-VBRJob objects .Id property
$session = Get-VBRBackupSession | ?{$_.JobId -eq $job.Id} | %{
$row = $table.NewRow()
$row.JobName = $_.JobName
$row.StartTime = $_.CreationTime
$row.StopTime = $_.EndTime
#Work out average speed in MB and round this to 0 decimal places, just like the Veeam GUI does.
$row.AvgSpeedMB = [Math]::Round($_.Progress.AvgSpeed/1024/1024,0)
#Duration is a Timespan value, so I am formatting in here using 3 properties - HH,MM,SS
$row.Duration = '{0:00}:{1:00}:{2:00}' -f $_.Progress.Duration.Hours, $_.Progress.Duration.Minutes, $_.Progress.Duration.Seconds
if ($_.Result -eq "Failed") {
#This is highlight is going to later be searched and replaced with HTML code to highlight failed jobs in RED :)
$row.Result = "#HIGHLIGHTRED"+$_.Result+"HIGHLIGHTRED#"
} else {
#Don't highlight if the backup session didn't fail.
$row.Result = $_.Result
}
#Add this calculated row to the $table.Rows
$table.Rows.Add($row)
}
$interestingsess = $table | Sort StartTime -descending | select -first 7
$pkc = 1
$interestingsess | foreach {
#for every object in $interestingsess (which has now been sorted by StartTime) assign the current value of $pkc to the .Index property. 1,2,3,4,5,6 etc...
$_.Index = $pkc
#Increment $pkc, so the next foreach loop assigns a higher value to the next .Index property on the next row.
$pkc+=1
}
#Now we are grabbing all the backup objects (same as viewing Backups in the Veeam B&R GUI Console
$backup = Get-VBRBackup | ?{$_.JobId -eq $job.Id}
$points = $backup.GetStorages() | sort CreationTime -descending | Select -First 7 #Find and assign the Veeam Backup files for each job we are going through and sort them in descending order. Select the specified amount.
#Increment variable is set to 1 to start off
$ic = 1
ForEach ($point in $points) {
#Match the $ic (Increment variable) up with the Index number we kept earlier, and assign $table to $rows where they are the same. This happens for each object in $points
$rows = $table | ?{$_.Index -eq $ic}
#inner ForEach loop to assign the value of the backup point's filename and VMs to the row's .FileName property as well as the creation time.
ForEach ($row in $rows) {
$Backups = Get-VBRBackup | ?{$_.JobId -eq $job.Id}
$vms =
foreach ($Backup in $Backups) {
$Backup.GetObjects() | Select Name
}
$vms1 = $vms | out-string
$vms1 = $vms1.replace(" " , "")
$vms1 = $vms1.replace("Name" , "")
$vms1 = $vms1.replace("----" , "")
$vms1 = $vms1.replace("`r" , "")
$vms1 = $vms1.replace("`n" , ";")
$vms1 = $vms1.replace(";;;" , "")
$vms1 = $vms1.replace("; ; ;" , "")
$vms1 = $vms1.replace(" ;" , "; ")
($row.FileName = $point.FileName) -and ($row.CreationTime = $point.CreationTime) -and ($row.VMList = $vms1)
#Increment the $ic variable ( +1 )
$ic+=1
}
}
#Tally up the current results into our $Report Array (add them)
$Report += $interestingsess
}
#Now we select those values of interest to us and convert the lot into HTML, assigning the styling we defined at the beginning of this script too.
$Report = $Report | Select Index, JobName, VMList, StartTime, StopTime, FileName, CreationTime, AvgSpeedMB, Duration, Result| ConvertTo-HTML -head $style
#Interesting bit - replace the highlighted parts with HTML code to flag up Failed jobs.
$Report = $Report -replace "#HIGHLIGHTRED","<font color='red'><B>"
$Report = $Report -replace "HIGHLIGHTRED#","</font></B>"
#Finally, save the report to a file on your drive.
$Report | Set-Content C:\VBRpowershell\Veeam-Backup-Report.htm
-
- Novice
- Posts: 4
- Liked: never
- Joined: Nov 23, 2011 4:05 pm
- Full Name: Marcin Frycz
- Location: London, UK
- Contact:
Re: PowerShell - Get-VbrJob
@Shogan - Congrats on VCP5 (I had my exam in December)
@Andreas Neufert - I think your code is missing some things:
$vms =
$Backup.GetObjects() | Select Name
I might be wrong but i am getting some errors while trying to execute it.
Although i have tried to reference StoredSize from preferences it still not working for me:
$row.StoredSize = $_.Info.Progress.StoredSize
Any Ideas ?
@Andreas Neufert - I think your code is missing some things:
Code: Select all
ForEach ($row in $rows) {
$Backups = Get-VBRBackup | ?{$_.JobId -eq $job.Id}
$vms =
foreach ($Backup in $Backups) {
$Backup.GetObjects() | Select Name
}
$vms1 = $vms | out-string
$vms1 = $vms1.replace(" " , "")
$vms1 = $vms1.replace("Name" , "")
$vms1 = $vms1.replace("----" , "")
$vms1 = $vms1.replace("`r" , "")
$vms1 = $vms1.replace("`n" , ";")
$vms1 = $vms1.replace(";;;" , "")
$vms1 = $vms1.replace("; ; ;" , "")
$vms1 = $vms1.replace(" ;" , "; ")
($row.FileName = $point.FileName) -and ($row.CreationTime = $point.CreationTime) -and ($row.VMList = $vms1)
#Increment the $ic variable ( +1 )
$ic+=1
}
$Backup.GetObjects() | Select Name
I might be wrong but i am getting some errors while trying to execute it.
Although i have tried to reference StoredSize from preferences it still not working for me:
Code: Select all
$session = Get-VBRBackupSession | ?{$_.JobId -eq $job.Id} | %{
$row = $table.NewRow()
$row.JobName = $_.Info.JobName
$row.StartTime = $_.Info.CreationTime
$row.StopTime = $_.Info.EndTime
$row.StoredSize = $_.Info.Progress.StoredSize
#Work out average speed in MB and round this to 0 decimal places, just like the Veeam GUI does.
$row.AvgSpeedMB = [Math]::Round($_.Info.Progress.AvgSpeed/1024/1024,0)
#Duration is a Timespan value, so I am formatting in here using 3 properties - HH,MM,SS
$row.Duration = '{0:00}:{1:00}:{2:00}' -f $_.Info.Progress.Duration.Hours, $_.Info.Progress.Duration.Minutes, $_.Info.Progress.Duration.Seconds
if ($_.Info.Result -eq "Failed") {
#This is highlight is going to later be searched and replaced with HTML code to highlight failed jobs in RED :)
$row.Result = "#HIGHLIGHTRED"+$_.Info.Result+"HIGHLIGHTRED#"
} else {
#Don't highlight if the backup session didn't fail.
$row.Result = $_.Info.Result
}
#Add this calculated row to the $table.Rows
$table.Rows.Add($row)
}
Any Ideas ?
-
- VP, Product Management
- Posts: 7076
- Liked: 1510 times
- Joined: May 04, 2011 8:36 am
- Full Name: Andreas Neufert
- Location: Germany
- Contact:
Re: PowerShell - Get-VbrJob
Hi mfrycz,
I checked my code again.
Evenrything works without an error and the debuger in the powershell editor didn´t complain anything.
Can you please open the code in the powershell editor and execute it there. Please post the error here. THX.
CU Andy
I checked my code again.
Evenrything works without an error and the debuger in the powershell editor didn´t complain anything.
Can you please open the code in the powershell editor and execute it there. Please post the error here. THX.
CU Andy
-
- Veteran
- Posts: 293
- Liked: 19 times
- Joined: Apr 13, 2011 12:45 pm
- Full Name: Thomas McConnell
- Contact:
Re: PowerShell - Get-VbrJob
Just for clarity
Datasize = Size of the whole backup file
StoreSize = Size of the VM inside the backup file
you can grab the Datasize very easily but if you want each VM StoreSize then you would have to loop the GetTaskSession() output
Datasize = Size of the whole backup file
StoreSize = Size of the VM inside the backup file
you can grab the Datasize very easily but if you want each VM StoreSize then you would have to loop the GetTaskSession() output
Who is online
Users browsing this forum: No registered users and 20 guests