PowerShell script exchange
Post Reply
DamienL
Service Provider
Posts: 28
Liked: 1 time
Joined: Apr 24, 2019 7:25 am
Contact:

List Disks(imported)

Post by DamienL »

Hello,

I'm currently using powershell to collect all my jobs / Disks and so on
Is is possible to retrieve imported disk job and machine ?
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: List Disks(imported)

Post by jhoughes »

Here's a quick way to find backups which do not have an associated job ID, virtual machine backups type, and where it shows an object in the backup file.

It may not be 100% accurate depending on your environment and if something erroneous may still be reported in your database, but this should get you started:

Code: Select all

Get-VBRBackup | Where-Object {($_.JobId -eq '00000000-0000-0000-0000-000000000000') -AND ($_.JobType -eq 'Backup') -AND (($_.GetOIBs()) -ne $null)}
If you also want to list out the job name and included VMs, this will show that:

Code: Select all

$BackupsWithoutJobs = Get-VBRBackup | Where-Object {($_.JobId -eq '00000000-0000-0000-0000-000000000000') -AND ($_.JobType -eq 'Backup') -AND (($_.GetOIBs()) -ne $null)}
foreach ($backup in $BackupsWithoutJobs) {$backup.GetOibs() | Select @{n='JobName';e={$backup.Name}}, @{n='VMName';e={$_.Name}}}
Husband, Father, Solutions Architect, Geek Extraordinaire | @DenverVMUG, @AustinVMUG & @ATXPowerShell leader | VMware vExpert | Cisco Champion
DamienL
Service Provider
Posts: 28
Liked: 1 time
Joined: Apr 24, 2019 7:25 am
Contact:

Re: List Disks(imported)

Post by DamienL »

Thanks for the feedback !
I need to look in the database, there is no answer with your queries :(
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: List Disks(imported)

Post by jhoughes »

Running just this should get you any backups which don't have a valid job ID and are of a VM backup type.

Code: Select all

Get-VBRBackup | Where-Object {($_.JobId -eq '00000000-0000-0000-0000-000000000000') -AND ($_.JobType -eq 'Backup')}
Does that return any results?

If not, what about just this (will include any job type with no job ID):

Code: Select all

Get-VBRBackup | Where-Object {$_.JobId -eq '00000000-0000-0000-0000-000000000000'}
Husband, Father, Solutions Architect, Geek Extraordinaire | @DenverVMUG, @AustinVMUG & @ATXPowerShell leader | VMware vExpert | Cisco Champion
DamienL
Service Provider
Posts: 28
Liked: 1 time
Joined: Apr 24, 2019 7:25 am
Contact:

Re: List Disks(imported)

Post by DamienL »

Hello,
the second return Something :) !

I'll check with this one.

Thanks
DamienL
Service Provider
Posts: 28
Liked: 1 time
Joined: Apr 24, 2019 7:25 am
Contact:

Re: List Disks(imported)

Post by DamienL »

The thing is on findjob function the imported jobs did'nt returns.. :( Any idea ?
My code is the Following :

Code: Select all

$Jobs = @()
$VMsBackuped = @()
$JobsList = Get-VBRBackup | Where-Object {$_.IsEndpointBackup -eq $true}

ForEach ($Job in $JobsList) {
    $LastSession = $null
    $LastResult = ''
    $EndTime = $null
    $Site = ''
    $Enabled = 'YES'
    $Type = 'Backup'
    $Schedule = 'Manual'
    $PreviousRunLocal = $null
    $LatestRunLocal = $null
    $NumberOfRetry = 0
    $TargetHost = ''
    $TargetDrive = ''
    $Size = 0
    $FreeSpace = 0
    $JobFolderSize = 0
    $JobLastIncrementalFileSize = 0

    $JobName = $Job.JobName
    $ServersList = $Job.GetObjects()
    if ($Job.FindJob()) {

        $LastSession = $Job.FindJob().FindLastSession()
        $LastResult = $LastSession.Result.ToString()
        $EndTime = $LastSession.EndTime
        $TargetHost = $Job.GetTargetHost().Name
        $TargetDrive = $Job.GetRepositoryPath().Root

    } else {
        $LastSession = $null
        $LastResult = ''
        $EndTime = $null
        $TargetHost = ''
        $TargetDrive = ''
    }

    if ($LastResult -ne '') {

        $JobObject = New-Object System.Object
        $JobObject | Add-Member -type NoteProperty -name Site -Value $Site
        $JobObject | Add-Member -type NoteProperty -name JobName -Value $JobName
	    $JobObject | Add-Member -type NoteProperty -name LastResult -Value $LastResult
	    $JobObject | Add-Member -type NoteProperty -name EndTime -Value $EndTime
	    $JobObject | Add-Member -type NoteProperty -name Enabled -Value $Enabled
	    $JobObject | Add-Member -type NoteProperty -name Type -Value $Type
	    $JobObject | Add-Member -type NoteProperty -name Schedule -Value $Schedule
	    $JobObject | Add-Member -type NoteProperty -name PreviousRun -Value $PreviousRunLocal
	    $JobObject | Add-Member -type NoteProperty -name LatestRun -Value $LatestRunLocal
	    $JobObject | Add-Member -type NoteProperty -name NumberOfRetry -Value $NumberOfRetry
	    $JobObject | Add-Member -type NoteProperty -name TargetHost -Value $TargetHost
	    $JobObject | Add-Member -type NoteProperty -name TargetDrive -Value $TargetDrive
	    $JobObject | Add-Member -type NoteProperty -name Size -Value $Size
	    $JobObject | Add-Member -type NoteProperty -name FreeSpace -Value $FreeSpace
	    $JobObject | Add-Member -type NoteProperty -name JobFolderSize -Value $JobFolderSize
	    $JobObject | Add-Member -type NoteProperty -name JobLastIncrementalFileSize -Value $JobLastIncrementalFileSize
	    $Jobs += $JobObject
        ForEach ($Server in $ServersList) {
            $Name = $Server.Name
            $VMBackupedObject = New-Object System.Object
	        $VMBackupedObject | Add-Member -type NoteProperty -name Name -Value $Name
		    If ($Type -eq "Backup") {
			    $VMBackupedObject | Add-Member -type NoteProperty -name BackupJobName -Value $JobName
			    $VMBackupedObject | Add-Member -type NoteProperty -name BackupStatus -Value $LastResult
			    $VMBackupedObject | Add-Member -type NoteProperty -name BackupFinish -Value $EndTime
			    $VMBackupedObject | Add-Member -type NoteProperty -name ReplicJobName -Value ""
			    $VMBackupedObject | Add-Member -type NoteProperty -name ReplicStatus -Value ""
			    $VMBackupedObject | Add-Member -type NoteProperty -name ReplicFinish -Value ""
		    } ElseIf ($Type -eq "Replication") {
			    $VMBackupedObject | Add-Member -type NoteProperty -name BackupJobName -Value ""
			    $VMBackupedObject | Add-Member -type NoteProperty -name BackupStatus -Value ""
			    $VMBackupedObject | Add-Member -type NoteProperty -name BackupFinish -Value ""
			    $VMBackupedObject | Add-Member -type NoteProperty -name ReplicJobName -Value $JobName
			    $VMBackupedObject | Add-Member -type NoteProperty -name ReplicStatus -Value $LastResult
			    $VMBackupedObject | Add-Member -type NoteProperty -name ReplicFinish -Value $EndTime
		    }
            if ($NumberOfRetry -eq 0) {
                $Retry = 'NO'
            } else {
                $Retry = 'YES'
            }
		    $VMBackupedObject | Add-Member -type NoteProperty -name Retry -Value $Retry

		    $VMsBackuped += $VMBackupedObject
        }
    }
}


$Jobs | Export-Csv $JobListFile
$VMsBackuped | Export-Csv $VMsBackupedListFile
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: List Disks(imported)

Post by jhoughes »

If there is only a backup on disk and no matching job exists, then the FindJob method will fail, as there is no job for it to find.

From the looks of it, you are trying to find details of the last job run related to these backups

I'd first ask how many of these backups with no existing job do you have that you are trying to report on?

Secondly, were these agent jobs which were managed by VBR, or were these standalone agents just targeting the Veeam repository for backup?
Husband, Father, Solutions Architect, Geek Extraordinaire | @DenverVMUG, @AustinVMUG & @ATXPowerShell leader | VMware vExpert | Cisco Champion
DamienL
Service Provider
Posts: 28
Liked: 1 time
Joined: Apr 24, 2019 7:25 am
Contact:

Re: List Disks(imported)

Post by DamienL »

Hello,

These agents are managed by a central Veeam backup server (9.5U3a).

I have 2 machines in imported disks.
Post Reply

Who is online

Users browsing this forum: No registered users and 14 guests