PowerShell script exchange
Post Reply
cromero
Influencer
Posts: 12
Liked: never
Joined: May 04, 2016 6:39 pm
Full Name: Carlos Romero
Contact:

Powershell Backup Report and VMWare Tags

Post by cromero »

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"
  }
}
Shestakov
Veteran
Posts: 7328
Liked: 781 times
Joined: May 21, 2014 11:03 am
Full Name: Nikita Shestakov
Location: Prague
Contact:

Re: Powershell Backup Report and VMWare Tags

Post by Shestakov »

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!
EugeneK
Veeam Software
Posts: 170
Liked: 43 times
Joined: Mar 19, 2016 10:57 pm
Full Name: Eugene Kashperovetskyi
Location: Chicago, IL
Contact:

Re: Powershell Backup Report and VMWare Tags

Post by EugeneK » 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
VMCA, VCIX-DCV, vExpert
veremin
Product Manager
Posts: 20406
Liked: 2298 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Powershell Backup Report and VMWare Tags

Post by veremin »

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.
cromero
Influencer
Posts: 12
Liked: never
Joined: May 04, 2016 6:39 pm
Full Name: Carlos Romero
Contact:

Re: Powershell Backup Report and VMWare Tags

Post by cromero »

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!
dellock6
VeeaMVP
Posts: 6166
Liked: 1971 times
Joined: Jul 26, 2009 3:39 pm
Full Name: Luca Dell'Oca
Location: Varese, Italy
Contact:

Re: Powershell Backup Report and VMWare Tags

Post by dellock6 »

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
Principal EMEA Cloud Architect @ Veeam Software

@dellock6
https://www.virtualtothecore.com/
vExpert 2011 -> 2022
Veeam VMCE #1
veremin
Product Manager
Posts: 20406
Liked: 2298 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Powershell Backup Report and VMWare Tags

Post by veremin »

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.
cromero
Influencer
Posts: 12
Liked: never
Joined: May 04, 2016 6:39 pm
Full Name: Carlos Romero
Contact:

Re: Powershell Backup Report and VMWare Tags

Post by cromero »

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
veremin
Product Manager
Posts: 20406
Liked: 2298 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Powershell Backup Report and VMWare Tags

Post by veremin »

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.
cromero
Influencer
Posts: 12
Liked: never
Joined: May 04, 2016 6:39 pm
Full Name: Carlos Romero
Contact:

Re: Powershell Backup Report and VMWare Tags

Post by cromero »

Thanks!!!
veremin
Product Manager
Posts: 20406
Liked: 2298 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Powershell Backup Report and VMWare Tags

Post by veremin »

You're welcome. If any other question arises, let us know. Thanks.
mhaaksma
Novice
Posts: 5
Liked: never
Joined: Jun 29, 2017 2:39 pm
Full Name: Monica
Contact:

[MERGED] Get list of vms when backup contains tag

Post by mhaaksma »

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
tdewin
Veeam Software
Posts: 1818
Liked: 655 times
Joined: Mar 02, 2012 1:40 pm
Full Name: Timothy Dewin
Contact:

Re: Get list of vms when backup contains tag

Post by tdewin »

You can use find-vbrvientity together with the tag location:
powershell-f26/powershell-backup-report ... ml#p200081
robjohnston
Veeam Software
Posts: 165
Liked: 16 times
Joined: Jun 13, 2016 11:51 pm
Full Name: Rob Johnston
Contact:

Re: Powershell Backup Report and VMWare Tags

Post by robjohnston »

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
MaxKozlov
Influencer
Posts: 19
Liked: 5 times
Joined: Oct 26, 2017 12:52 pm
Full Name: Max Kozlov
Contact:

Re: Powershell Backup Report and VMWare Tags

Post by MaxKozlov »

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]
    }
}
Post Reply

Who is online

Users browsing this forum: No registered users and 19 guests