PowerShell script exchange
Post Reply
lhas
Novice
Posts: 4
Liked: never
Joined: Sep 09, 2020 7:34 am
Full Name: Lasse Hastrup
Contact:

Get report on a single VM

Post by lhas »

Hi guys,

I would like to get the following "attributes/values" for a specific Virtual Machine using PowerShell.

$vmName = 'xx'

Attributes to output:

MachineName
JobName(s)
RestorePoints
LastSuccess

Is this possible to achive using PowerShell?
To be honest i tried myself, but i wasnt able to figure it out.

Thanks in advance!
Andreas Neufert
VP, Product Management
Posts: 6747
Liked: 1407 times
Joined: May 04, 2011 8:36 am
Full Name: Andreas Neufert
Location: Germany
Contact:

Re: Get report on a single VM

Post by Andreas Neufert »

lhas
Novice
Posts: 4
Liked: never
Joined: Sep 09, 2020 7:34 am
Full Name: Lasse Hastrup
Contact:

Re: Get report on a single VM

Post by lhas »

Hi Andreas,
Yea, i found that article aswell, however it doesn't give me what i desire the outcome to be.
It seems I need to use 10 different functions to get the output i desire, because for some reason using PowerShell with Veeam should be complicated :)
jhoughes
Veeam Vanguard
Posts: 279
Liked: 112 times
Joined: Apr 20, 2017 4:19 pm
Full Name: Joe Houghes
Location: Castle Rock, CO
Contact:

Re: Get report on a single VM

Post by jhoughes »

Well, part of it is because of the detail that you are asking to find and your source information.

With a single VM, you are asking about a job object. However, even your VM jobs may not include VMs directly, but they may target folders, clusters, datastores, or tags.

To accurately get the list of restore points for a single VM and that detail, it is best to start with your backups.

You would gather the detail of which VMs are within the backups (plus job name and last success), and then get the associated restore points for the particular VM in that backup.

It's just that you are looking for a single VM to be the basis of your query, which either requires investigating every vSphere job object that isn't a VM directly, or starting with the backup data to determine the objects contained within a backup.

This is all easy, but there is no simple cmdlet to investigate from a single VM perspective.
Husband, Father, Solutions Architect, Geek Extraordinaire | @DenverVMUG, @AustinVMUG & @ATXPowerShell leader | VMware vExpert | Cisco Champion
lhas
Novice
Posts: 4
Liked: never
Joined: Sep 09, 2020 7:34 am
Full Name: Lasse Hastrup
Contact:

Re: Get report on a single VM

Post by lhas »

Thanks for responding.

Yea, i guess you're right. It's different functions for diffrent purposes. I had hoped that something like Find-VBRViEntity would do the trick.
Do you have any sample code that give me the desired output?
oleg.feoktistov
Veeam Software
Posts: 1918
Liked: 636 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Get report on a single VM

Post by oleg.feoktistov »

Hi Lasse,

If you are still looking for an example, here is one I composed from my old scripts.
It's a bit rough, so, please, amend anything if necessary:

Code: Select all


# Pull backup by its name
 $backup = Get-VBRBackup -Name 'BackupName'
    $summary = @()

# Get objects in backup.
    $objects = $backup.GetObjects()
    $sessions = Get-VBRBackupSession -Name 'BackupName*'

# Query each object and get relevant restore points and last success date.
    foreach($object in $objects) {
        $rps = Get-VBRRestorePoint -Backup $backup -Name $object.Name
        $taskSessionsTotal = @()
        foreach($session in $sessions) {
            $taskSessions = Get-VBRTaskSession -Session $session -Name $object.Name | where {$_.Status -eq 'Success'}
            $taskSessionsTotal += $taskSessions
    
        }

        $lastSession = $taskSessionsTotal | select @{n='CompletionTimeLocal';e={$_.Info.Progress.StopTimeLocal}} -Last 1

# Construct a new object and add it to an empty $summary array.
          $summary += $object | select @{n='MachineName';e={$object.Name}}, @{n='JobName';e={$backup.Name}}, @{n='RestorePoints';e={$rps.Id}}, @{n='LastSuccess';e={$lastSession.CompletionTimeLocal}} 
    

    }

# Get summary array with constructed objects.
    $summary | fl
Hope that helps,
Oleg
lhas
Novice
Posts: 4
Liked: never
Joined: Sep 09, 2020 7:34 am
Full Name: Lasse Hastrup
Contact:

Re: Get report on a single VM

Post by lhas »

Thanks a lot!!
Post Reply

Who is online

Users browsing this forum: No registered users and 14 guests