PowerShell script exchange
Post Reply
GJemmotte85
Novice
Posts: 5
Liked: never
Joined: Aug 06, 2019 3:59 pm
Full Name: Gavin Jemmotte
Contact:

List VMs only from Backup to Tape and Backup Copy

Post by GJemmotte85 »

I am quite new to powershell, having difficulty getting list of VMs that would only include Jobs from Backup to Take and Backup Copy. I have below so far:

Code: Select all

asnp "VeeamPSSnapIn"
$myObject = New-Object PSObject
$TapeJobs = Get-VBRTapeJob 
#Get-VBRTapeJob | select Object 

#Clear Variables
$resultsarray=@()

foreach ($TapeJob in $TapeJobs)
{
    if ($TapeJob.LastResult -eq "Success")
    {
        $NameofTapeJob = $TapeJob.Name
        $ReplicationJobName = $NameofTapeJob -replace " to Tape"
        #write-host $ReplicationJobName
        $VMs = Get-VBRJob -Name $ReplicationJobName | Get-VBRJobObject
        
        foreach ($VM in $VMs)
        {
            write-host $VM.Name
            $backupObject = New-Object PSObject
            $backupObject | Add-Member -MemberType NoteProperty -name "Server" -Value $VM.Name
            $resultsarray += $backupObject
        }
    }   
}
veremin
Product Manager
Posts: 20282
Liked: 2257 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: List VMs only from Backup to Tape and Backup Copy

Post by veremin »

What is selected as a source for backup to tape and backup copy jobs? Backup jobs, individual VMs (in case of backup copy job), backup repository, etc.? Thanks!
GJemmotte85
Novice
Posts: 5
Liked: never
Joined: Aug 06, 2019 3:59 pm
Full Name: Gavin Jemmotte
Contact:

Re: List VMs only from Backup to Tape and Backup Copy

Post by GJemmotte85 »

Thanks for the response.

Source for 3 of back up to tape are Hyper-V Backup e.g. Location App Server (Hyper-V Backup) and Backup to Tape Location App Servers to Tape.
Source Backup Copy are VMs e.g. 1st Location Replicated to 2nd Location and it is run continuously.

Reason why require to find out VMs for Backup Copy is that 1 of the Backup to tape source is a Backup Copy.

e.g. Tape Job from Backup Copy Job from VM

That make sense?
veremin
Product Manager
Posts: 20282
Liked: 2257 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: List VMs only from Backup to Tape and Backup Copy

Post by veremin »

This is how you can get source object of backup to tape job:

Code: Select all

$Job = Get-VBRTapeJob -name "Name of your backup to tape job"
$Job. Object | Select name
This is how you can get source object of backup to copy job:

Code: Select all

$Job = Get-VBRJob -name "Backup Copy Job 1"
$Job | Get-VBRJobObject | Select name
I'm writing the scripts from memory; so, some modification might be needed.

Thanks!
GJemmotte85
Novice
Posts: 5
Liked: never
Joined: Aug 06, 2019 3:59 pm
Full Name: Gavin Jemmotte
Contact:

Re: List VMs only from Backup to Tape and Backup Copy

Post by GJemmotte85 »

Thanks, have changed to below:

Code: Select all

asnp "VeeamPSSnapIn"
$myObject = New-Object PSObject
#Get Jobs
$Jobs = Get-VBRTapeJob

#Clear Variables
$resultsarray=@()

foreach ($Job in $Jobs)
{
    if ($Jobs.LastResult -eq "Success")
    {
      #Get VMs from source jobs
      $SourceJobs = $Jobs.Object | Get-VBRJobObject | Select Name | Format-Table
      $VMs = $jobs.object | Get-VBRJobObject | Select Name

      foreach ($VM in $VMs)
        {
        #Write-Host
            write-host $VM.Name
            $backupObject = New-Object PSObject
            $backupObject | Add-Member -MemberType NoteProperty -name "Server" -Value $VM.Name
            $resultsarray += $backupObject
            }
     }
}

#Results are sent to csv file
$resultsarray | Convert-OutputForCSV | Export-Csv "\\hartwdb01\CheckListData\Weekly\Backup Verify\Edinburgh-Veeam2018test.csv" -NoTypeInformation
Output is good shows VMs from each source. It duplicates the output 3 times
veremin
Product Manager
Posts: 20282
Liked: 2257 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: List VMs only from Backup to Tape and Backup Copy

Post by veremin »

Not sure about your last comment - is everything OK with the script or you need any further assistance in modifying the script output? Thanks!
GJemmotte85
Novice
Posts: 5
Liked: never
Joined: Aug 06, 2019 3:59 pm
Full Name: Gavin Jemmotte
Contact:

Re: List VMs only from Backup to Tape and Backup Copy

Post by GJemmotte85 »

Apologies, Issue i have is the Output is duplicated 3 extra times.

Thanks you
veremin
Product Manager
Posts: 20282
Liked: 2257 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: List VMs only from Backup to Tape and Backup Copy

Post by veremin »

I would:

- check whether the same VMs are not present inside different backup jobs that are selected as source for backup to tape jobs
- re-write the script slightly:

Code: Select all

asnp "VeeamPSSnapIn"
$myObject = New-Object PSObject
$Jobs = Get-VBRTapeJob | where {$_.LastResult -eq "Success"}
$resultsarray=@()
foreach ($Job in $Jobs)
{
      $VMs = $Job.object | Get-VBRJobObject | Select Name
      foreach ($VM in $VMs)
        {
        #Write-Host
            write-host $VM.Name
            $backupObject = New-Object PSObject
            $backupObject | Add-Member -MemberType NoteProperty -name "Server" -Value $VM.Name
            $resultsarray += $backupObject
        }

}

#Results are sent to csv file
$resultsarray | Convert-OutputForCSV | Export-Csv "\\hartwdb01\CheckListData\Weekly\Backup Verify\Edinburgh-Veeam2018test.csv" -NoTypeInformation
Thanks!
GJemmotte85
Novice
Posts: 5
Liked: never
Joined: Aug 06, 2019 3:59 pm
Full Name: Gavin Jemmotte
Contact:

Re: List VMs only from Backup to Tape and Backup Copy

Post by GJemmotte85 »

Thanks that was perfect much appreciated
veremin
Product Manager
Posts: 20282
Liked: 2257 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: List VMs only from Backup to Tape and Backup Copy

Post by veremin »

You're welcome.

I think you've made a mistake in these lines:

1. Here you declare a variable that you don't use anywhere else

Code: Select all

$SourceJobs = $Jobs.Object | Get-VBRJobObject | Select Name | Format-Table
2. Here instead of $Job variable you use $Jobs one, which makes output multipled:

Code: Select all

$VMs = $jobs.object | Get-VBRJobObject | Select Name
Thanks!
Post Reply

Who is online

Users browsing this forum: No registered users and 8 guests