Powershell Backup Report and VMWare Tags

PowerShell script exchange

Powershell Backup Report and VMWare Tags

Veeam Logoby cromero » Tue May 10, 2016 2:07 pm

Hi!

I need an script that checks that specified machines have backup (Domain Controllers)

I'm working in the attached script but the problem is that in VMWare we are using tags and the script is can't check the tags so is returning these machines as "not backed up"

Do you know how can I work with this issue?

Thanks!

Code: Select all
#Get all machines in all Jobs

$JobObjects = Get-VBRJob -name * | Get-VBRJobObject | select name

$hash = @{};

#Clean hash table

$hash.clear()

foreach ($jobObject in $JobObjects){

$hash.add($jobObject.name, "Unprotected")

}


#$Machines = $JobObject.name




# Find all backup job sessions that have ended in the last 24 hours

$vbrsessions = Get-VBRBackupSession | Where-Object {$_.JobType -eq "Backup" -and $_.EndTime -ge (Get-Date).addhours(-24)}

# Find all successfully backed up VMs in selected sessions (i.e. VMs not ending in failure) and update status to "Protected"

foreach ($session in $vbrsessions) {
    foreach ($JobObject in ($session.GetTaskSessions() | Where-Object {$_.Status -ne "Failed"} | ForEach-Object { $_ })) {
        if($hash.containskey($Jobobject.Name)) {
            $hash[$JobObject.Name]="Protected"
        }
    }
}

# Output Machines in color coded format based on status.
foreach ($caca in $hash.Keys)
{
  if ($hash[$caca] -eq "Protected") {
      write-host -foregroundcolor green "$caca is backed up"
  } else {
      write-host -foregroundcolor red "$caca is NOT backed up"
  }
}
cromero
Novice
 
Posts: 9
Liked: never
Joined: Wed May 04, 2016 6:39 pm
Full Name: Carlos Romero

Re: Powershell Backup Report and VMWare Tags

Veeam Logoby Shestakov » Wed May 11, 2016 4:06 pm

Hi Carlos and welcome to the forums!
While waiting for others to assist with a script, I would suggest to leverage Veeam ONE capabilities to reach the goal.
You may use Protected VMs report to check which VMs don`t have backups. You can also run for particular groups creating them in Business View.
Thanks!
Shestakov
Veeam Software
 
Posts: 5781
Liked: 495 times
Joined: Wed May 21, 2014 11:03 am
Location: Saint Petersburg
Full Name: Nikita Shestakov

Re: Powershell Backup Report and VMWare Tags

Veeam Logoby EugeneK » Wed May 11, 2016 5:15 pm 1 person likes this post

In addition to Protected VMs report, I absolutely also love to use the VM Backup Status one:
https://helpcenter.veeam.com/one/report ... tatus.html
Eugene K
Product Architect @ SingleHop - Veeam Platinum Service Provider
http://www.singlehop.com
VCAP-DCD, VCAP-DCA, VCP-NV
Veeam Certified Architect
EugeneK
Veeam Vanguard
 
Posts: 104
Liked: 24 times
Joined: Sat Mar 19, 2016 10:57 pm
Location: Chicago, IL
Full Name: Eugene Kashperovetskyi

Re: Powershell Backup Report and VMWare Tags

Veeam Logoby v.Eremin » Tue May 17, 2016 3:05 pm

I think you will have to create two lists and try to compare them. First list should contain list of VMs that have a corresponding tag assigned to them, second - list of VMs backed up recently. Thanks.
v.Eremin
Veeam Software
 
Posts: 14812
Liked: 1113 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Powershell Backup Report and VMWare Tags

Veeam Logoby cromero » Tue May 31, 2016 1:27 pm

v.Eremin wrote:I think you will have to create two lists and try to compare them. First list should contain list of VMs that have a corresponding tag assigned to them, second - list of VMs backed up recently. Thanks.


Hi guys,

Thanks for your answers! v.Eremin, do you know the command to extract the VM machines from Veeam? I can manage to extract the machines with specific Tag from VMWare but I can't extract vm machines from vm machines lists in veeam.

I know we have Get-VBRJob -name * | Get-VBRJobObject | select name to extract machines inside jobs, but here I get the tags.

Thanks!
cromero
Novice
 
Posts: 9
Liked: never
Joined: Wed May 04, 2016 6:39 pm
Full Name: Carlos Romero

Re: Powershell Backup Report and VMWare Tags

Veeam Logoby dellock6 » Tue May 31, 2016 7:06 pm

Maybe this script can be a good starting point for your need?
http://www.virtualtothecore.com/en/back ... 6-edition/
(thanks to Tom Sightler for the script itself, I just posted it in my blog)
Luca Dell'Oca
EMEA Cloud Architect @ Veeam Software

@dellock6
http://www.virtualtothecore.com/en/
vExpert 2011-2012-2013-2014-2015-2016-2017-2018
Veeam VMCE #1
dellock6
Veeam Software
 
Posts: 5374
Liked: 1460 times
Joined: Sun Jul 26, 2009 3:39 pm
Location: Varese, Italy
Full Name: Luca Dell'Oca

Re: Powershell Backup Report and VMWare Tags

Veeam Logoby v.Eremin » Thu Jun 02, 2016 12:42 pm

I can manage to extract the machines with specific Tag from VMWare but I can't extract vm machines from vm machines lists in veeam.

VMs having specific tag can be returned via similar script:

Code: Select all
Find-VBRViEntity -Server $server -Tags -Name "Name of your tag"


The second list I was talking about would be created based on the task sessions (you have this portion already in your original script).

Thanks.
v.Eremin
Veeam Software
 
Posts: 14812
Liked: 1113 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Powershell Backup Report and VMWare Tags

Veeam Logoby cromero » Mon Jun 27, 2016 7:20 pm

Thanks v.Eremin,

Tried this but it's not returning me the machines with the specific tag "test". I only got this:

Code: Select all
ConnHost  : Veeam.Backup.Core.Common.CHost
Type      : Tag
Reference : urn:vmomi:InventoryServiceTag:8xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
TagQsId   : urn:vmomi:InventoryServiceTag:8xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Id        : dxxxxxxxxxxxxxxxxxxxxx
Name      : test
Path      : servername\General\test
cromero
Novice
 
Posts: 9
Liked: never
Joined: Wed May 04, 2016 6:39 pm
Full Name: Carlos Romero

Re: Powershell Backup Report and VMWare Tags

Veeam Logoby v.Eremin » Fri Jul 01, 2016 2:33 pm

The provided example has to be modified a bit in order to meet your goal. Check the script below:

Code: Select all
$TagPath = (Find-VBRViEntity -Tags -name "Name of your Tag").Path
Find-VBRViEntity -Tags | where {$_.Type -eq "VM" -and $_.path -like "$TagPath*"} | select name


Thanks.
v.Eremin
Veeam Software
 
Posts: 14812
Liked: 1113 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Powershell Backup Report and VMWare Tags

Veeam Logoby cromero » Mon Jul 04, 2016 7:46 pm

Thanks!!!
cromero
Novice
 
Posts: 9
Liked: never
Joined: Wed May 04, 2016 6:39 pm
Full Name: Carlos Romero

Re: Powershell Backup Report and VMWare Tags

Veeam Logoby v.Eremin » Tue Jul 05, 2016 8:41 am

You're welcome. If any other question arises, let us know. Thanks.
v.Eremin
Veeam Software
 
Posts: 14812
Liked: 1113 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

[MERGED] Get list of vms when backup contains tag

Veeam Logoby mhaaksma » Wed Aug 09, 2017 9:01 pm

How can I get the list of vms when the backup job contains tags?

PS C:\Users\xxxxx> (Get-VBRJob -Name "Ztest_Backup_Job_Post_Script" | Sort -Property Name).GetObjectsInJob() | ?{$_.Type -eq "Include"}

Name Type ApproxSize Location
---- ---- ---------- --------
1 - 15 to 30 minutes Include 50.0 GB xxxx-vc2\Criticality\1...

I would like only the VMs associated with that backup job.

Any help will greatly be appreciated.
Thank you,
Monica
mhaaksma
Novice
 
Posts: 5
Liked: never
Joined: Thu Jun 29, 2017 2:39 pm
Full Name: Monica

Re: Get list of vms when backup contains tag

Veeam Logoby tdewin » Thu Aug 10, 2017 7:19 am

You can use find-vbrvientity together with the tag location:
powershell-f26/powershell-backup-report-and-vmware-tags-t35176.html#p200081
tdewin
Veeam Software
 
Posts: 1280
Liked: 421 times
Joined: Fri Mar 02, 2012 1:40 pm
Full Name: Timothy Dewin

Re: Powershell Backup Report and VMWare Tags

Veeam Logoby robjohnston » Tue Feb 13, 2018 2:06 am

Hi guys,

I need something similar for a customer that needs an email sent every morning for all of their Tier 1 apps (around 40 servers in total).

Customer has critical servers tagged as "critical" in vsphere.
They want an email sent to the backup admins every morning listing all critical servers with the VM Tag "critical" and their backup status of the previous day. I want to only include the critical VM's with the tag "Critical". They are spread over many different backup jobs, hosts and clusters.

Is this possible?

Thanks,

Rob
robjohnston
Veeam Software
 
Posts: 36
Liked: 4 times
Joined: Mon Jun 13, 2016 11:51 pm
Full Name: Rob Johnston

Re: Powershell Backup Report and VMWare Tags

Veeam Logoby MaxKozlov » Tue Feb 13, 2018 8:18 am

Find-VBRLastTaggedBackupTaskSession.ps1
Code: Select all
<#
    .SYNOPSIS
        Find last backup session for tagged VM's
    .NOTES
        Author: Max Kozlov
#>
[CmdletBinding()]
#Requires -Version 4.0
param(
    [Parameter(Mandatory)]
    [string[]]$Tag,
    [switch]$PowerCli
)
Write-Verbose 'Get tagged entities'
# Here, we can get tagged VMs by Powercli. It works alot faster than Veeam
if ($PowerCli) {
    $tagentities = Get-VM -Tag (Get-Tag -Name $Tag )
}
else {
    $tags = Find-VBRViEntity -Tags -Name $Tag
    $tagentities = Find-VBRViEntity -Tags |
    Where-Object {
        $o=$_
        $o.Type -eq 'VM' -and ( $tags | Where-Object { $o.Path.StartsWith($_.Path) } ) -ne $null
}
}

Write-Verbose 'Get job list'
$jobs = Get-VBRJob  | Where-Object { $_.IsBackupJob }
$lastsessions = $jobs.FindLastSession()
$lasttasks = $lastsessions | Get-VBRTaskSession | Group-Object -AsHashTable -Property Name

Write-Verbose 'Compare job objects and tagged entities'
foreach ($e in $tagentities) {
    if ($lasttasks.ContainsKey($e.Name)) {
        $lastTasks[$e.Name]
    }
}
MaxKozlov
Influencer
 
Posts: 10
Liked: 2 times
Joined: Thu Oct 26, 2017 12:52 pm
Full Name: Max Kozlov


Return to PowerShell



Who is online

Users browsing this forum: No registered users and 6 guests