PowerShell script exchange
Post Reply
adrien.vanackere
Lurker
Posts: 2
Liked: never
Joined: Dec 05, 2017 2:50 pm
Full Name: Adrien VANACKERE
Contact:

Improve my current Veeam Backup & Replication/Cloud script

Post by adrien.vanackere »

Hello,

I'm currently trying to improve my powershell script that allowed me to monitor the best way possible my veeam jobs and copy jobs for all my customers.

So I have a script that I have implemented in Solarwinds N-Central that works but I have some issues and things to improve on it:

The script :

Add-PSSnapin veeampssnapin
$Sessions = Get-VBRBackupSession #get all of the session information
$Jobs = $Sessions.JobName | select -uniq #get a list of unique backup job names
$numJobs = $Jobs.count #count the number of unique backup jobs
#write-output $numJobs
#write-output $Jobs

$report = @() #declare a blank array
foreach ($session in $Sessions){ #loop through the backup jobs and write the inforamtion into the array
$Info = [Veeam.Backup.Core.CBackupTaskSession]::GetByJobSession($session.id)
$report += $Info

}



$uBackups = $report | Group-Object 'ObjectName' | ForEach-Object{$_.Group | Sort-Object QueuedTime -Descending | Select 'QueuedTime', 'ObjectName', 'Status', 'Reason' -First 1}



for ($n=0; $n -lt $uBackups.count; $n++)
{if ($uBackups[$n].ObjectName -eq $jName) {
$qt = $uBackups[$n].QueuedTime
$obN = $uBackups[$n].ObjectName
$st = $uBackups[$n].Status
$r = $uBackups[$n].Reason
}}


The parameters :

In order to use input/output parameter inside the script, user must provide its name, preceded by $.
Example: parameter named InputParameter must be referred to as $InputParameter to be recognized by the script engine.

Input Parameters:
$jName

Output Parameters:
$qt
$obN
$st
$r

---------------------------------------------------------------------------

1) With this script I have to provide the name in my tool for each virtual machines that I have. Do you have a way to autoprovide the VM name for each jobs ?
3) Get informations only from the last month.
2) I would like to implement the 'Next RUN' and 'TARGET' infos for each jobs that was found. That is possible to do it with this script ?

best Regards
veremin
Product Manager
Posts: 20284
Liked: 2258 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Improve my current Veeam Backup & Replication/Cloud scri

Post by veremin »

1) With this script I have to provide the name in my tool for each virtual machines that I have. Do you have a way to autoprovide the VM name for each jobs ?
Query vCenter server with Find-VBRViEntity cmdlet, use $_.Type -eq "VM" as filter option (you can double check the syntax on PowerShell subforum; there should be plenty of examples) .
2) I would like to implement the 'Next RUN' and 'TARGET' infos for each jobs that was found. That is possible to do it with this script ?
Kindly, check previous threads, as this topic has been discussed several times already.
3) Get informations only from the last month.
Filter task sessions based on CreationTime parameter (you need only ones created within the last 30 days or so; current date - 30 days).

Thanks.
Post Reply

Who is online

Users browsing this forum: No registered users and 13 guests