PowerShell script exchange
Post Reply
xefil
Enthusiast
Posts: 39
Liked: never
Joined: Jan 13, 2012 8:08 am
Contact:

List of VMs in jobs - question about Get-VBRJob

Post by xefil »

Hi all,

I'm using this script to have a list of VMs into all Jobs, with following code:

Code: Select all

$JobNumber=0
$VMNumber=0
$JobList = Get-VBRJob | ?{$_.JobType -eq "Backup"}
foreach($Jobobject in $JobList) {
	$JobName = $Jobobject.Name
	Write-Host "JOB: $JobName"
	$JobNumber++
	$VMList = $JobObject.GetObjectsInJob()
	foreach($VMObject in $VMList) {
		$VMName = $VMObject.name
		Write-Host " ---> VMName: $VMName"
		$VMNumber++
	}
}
What happens:
If the job contains a Folder or Resource Pool the $VMName contains not the VMs, but only the RP name.
And the vApps are never counted.

How to count VMs and/or vApps editing what above?

Thanks!

Simon

oleg.feoktistov
Veeam Software
Posts: 619
Liked: 218 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: List of VMs in jobs - question about Get-VBRJob

Post by oleg.feoktistov »

Hi,

Job object is always an entity you added directly, with no child ones in regards to VBR side.
But you can still check and count your VMs/vApps within resource pools, folders etc. added as job objects using PowerCLI.

Thanks,
Oleg

xefil
Enthusiast
Posts: 39
Liked: never
Joined: Jan 13, 2012 8:08 am
Contact:

Re: List of VMs in jobs - question about Get-VBRJob

Post by xefil »

Hello,

Would it possible to have an example?

Thanks a lot!

Simon

jhoughes
Veeam Software
Posts: 224
Liked: 78 times
Joined: Apr 20, 2017 4:19 pm
Full Name: Joe Houghes
Location: Austin, TX
Contact:

Re: List of VMs in jobs - question about Get-VBRJob

Post by jhoughes »

It would be better to search for these examples on the VMware{code} or VMTN forums.

Here's a quick thread with a good example from Luc Dekens which will address this for you:
https://code.vmware.com/forums/2530/vsp ... cli#543150
Husband, Father, Solutions Architect, Geek Extraordinaire | @AustinVMUG & @ATXPowerShell leader | VMUG US South Regional Champion | VMware vExpert | Cisco Champion

aantonacci@shci.ca
Novice
Posts: 6
Liked: never
Joined: Oct 19, 2020 7:42 pm
Full Name: Anthony Antonacci
Contact:

Re: List of VMs in jobs - question about Get-VBRJob

Post by aantonacci@shci.ca »

I have a similar issue on HyperV

If i add the host it will backup all the VM.
But get-vbrjobobject will not list the VM in the backupjob instead it will only list different properties (if i changed a vss setting on one of the VM, if i excluded it, if i needed to provide credentials)
is there a way to get a list of the VM in the host object i'm backing up?

oleg.feoktistov
Veeam Software
Posts: 619
Liked: 218 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: List of VMs in jobs - question about Get-VBRJob

Post by oleg.feoktistov »

Hi Anthony,

It's the same strategy but with Hyper-V Powershell Module. Get host name and then get VMs running on this host:

Code: Select all

$job = Get-VBRJob -Name 'BackupJob'
$object = Get-VBRJobObject -Job $job
$vms = Get-VM -ComputerName $object.Name -Credential $creds
Make sure hyper-v ps module is installed on the instance you're running the script from or else use ps remoting to hyper-v host to get vm names.

Thanks,
Oleg

shuum
Lurker
Posts: 2
Liked: never
Joined: Oct 20, 2020 1:33 pm
Full Name: Andrey V. Shmagai
Location: Russia, Novosibirsk
Contact:

Re: List of VMs in jobs - question about Get-VBRJob

Post by shuum »

Good afternoon Oleg, I tried to repeat this recipe in order to get the names of all hosts in a job with the "Windows Agent Backup" type and nothing came of it, out of 18 hosts actually listed in the job, only one returned, and that is not a real one, but only a domain name from real host (host is "example.tutu.ru" - i see "tutu.ru" only). Can you tell me how to get hostnames in a task with the "Windows Agent Backup" type. Thank you.
Если можно, я могу объяснить по русски, может будет понятнее :)
- And when it seemed to me that I was tied up, they dragged me back.

oleg.feoktistov
Veeam Software
Posts: 619
Liked: 218 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: List of VMs in jobs - question about Get-VBRJob

Post by oleg.feoktistov »

Hi Andrey,

It's the rule of our forums to post messages in english only so that everybody, who's having the same issue, would understand.
If you want to discuss something specifically in russian, though, you can send me a personal message on the forum.

Thanks,
Oleg

oleg.feoktistov
Veeam Software
Posts: 619
Liked: 218 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: List of VMs in jobs - question about Get-VBRJob

Post by oleg.feoktistov »

@shuum,

As for your question. Have you added hosts separately to the job or as an entire protection group?
How are the hosts inside protection group being reflected?

Thanks,
Oleg

shuum
Lurker
Posts: 2
Liked: never
Joined: Oct 20, 2020 1:33 pm
Full Name: Andrey V. Shmagai
Location: Russia, Novosibirsk
Contact:

Re: List of VMs in jobs - question about Get-VBRJob

Post by shuum »

@oleg.feoktistov ,

Thanks Oleg, let's not break the rules and continue in English.
The hosts are added to the job as a "Protection group". Hosts are reflected in the group as active directory domain objects. On the "Type" tab of this protection group is: "This protection group will contain: (checkbox) Microsoft active directory objects".
- And when it seemed to me that I was tied up, they dragged me back.

oleg.feoktistov
Veeam Software
Posts: 619
Liked: 218 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: List of VMs in jobs - question about Get-VBRJob

Post by oleg.feoktistov »

Then the strategy is different here as well. You need to retrieve the name of protection group added to the job and then get included hosts. It's not possible to query hosts inside protection group recursively with Get-VBRJobObject since job objects has no sublevels. You can query them though given they are all added directly to the job. Example with protection group:

Code: Select all

$job = Get-VBRComputerBackupJob -Name 'TEST'
$objects = Get-VBRJobObject -job $job
$pg = Get-VBRProtectionGroup -Name 'Active Directory - HQ Computers'
$hosts = Get-VBRDiscoveredcomputer -ProtectionGroup $pg 
Thanks!

aantonacci@shci.ca
Novice
Posts: 6
Liked: never
Joined: Oct 19, 2020 7:42 pm
Full Name: Anthony Antonacci
Contact:

Re: List of VMs in jobs - question about Get-VBRJob

Post by aantonacci@shci.ca »

Hi Oleg,
"It's the same strategy but with Hyper-V Powershell Module. Get host name and then get VMs running on this host:"
Wont work in this case , we have one Veeam Server backing up 4 HV servers... so the Get-VM command wont list all the VM....

From what I understand (i am very new at PS for VEEAM). If you select the hyper-V host as an backup object in the GUI (not each VM), it wont list all the VM with the object command, it will only list objects that you specify the credentials, or it you excluded a machine, or if you set specific VSS setting for a perticular machine. if non of these boxes are ticked no VM will come up.
if for example you have a customer that has a Hyper-V that is joined to the Domain and in the host there is 3 member servers, you do not need to specify credentials... in this case there will be no objects....


I am grabbing session tasks to get the VM that are being backed up....

oleg.feoktistov
Veeam Software
Posts: 619
Liked: 218 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: List of VMs in jobs - question about Get-VBRJob

Post by oleg.feoktistov »

Hi Anthony,

Your understanding is correct. To list vms for all 4 Hyper-V hosts added as includes directly to a job, you would need to query 4 of them separately for the list of VMs:

Code: Select all

$job = Get-VBRJob -Name 'BackupJob'
$objects = Get-VBRJobObject -Job $job
$vmList = @()
foreach ($object in $objects) {
      $vms = Get-VM -ComputerName $object.Name -Credential $creds
      $vmList += $vms
}
Task sessions is a bit different story since they reflect objects, which are already backed up. Whereas this whole thread is about retrieving job objects.

Thanks!

aantonacci@shci.ca
Novice
Posts: 6
Liked: never
Joined: Oct 19, 2020 7:42 pm
Full Name: Anthony Antonacci
Contact:

Re: List of VMs in jobs - question about Get-VBRJob

Post by aantonacci@shci.ca »

Yes. What I am stating is depending on how you setup your Backup Job, using the objects WONT work (unless i'm doing something wrong here)

For example:
Create a backup job and add only local host.
use local host credential to backup guests

Run following:

Code: Select all

$job=Get-VbrJob -name 'Daily 30' 
$objects = Get-VBRJobobject -job $job
foreach ($obj in $objects) { $obj.name}
you will see only: localhost
instead of all the VM...

Worse if you exclude a VM from the list, you will get a Eexclude Object... (so the vm you are listing is Excluded from the list...)

oleg.feoktistov
Veeam Software
Posts: 619
Liked: 218 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: List of VMs in jobs - question about Get-VBRJob

Post by oleg.feoktistov »

Exactly, we are talking about the same thing. That's why I mentioned the strategy, when you connect to the backed up host directly and list every VM hosted there. Thanks!

pierardy
Novice
Posts: 7
Liked: never
Joined: Sep 26, 2020 1:28 pm
Full Name: Yves Pierard
Contact:

Re: List of VMs in jobs - question about Get-VBRJob

Post by pierardy »

Here, my PS script to get VM in jobs:
I am using Specific job names


#VM/HyperV in jobs:

Code: Select all


$DesktopPath = [Environment]::GetFolderPath("Desktop")
$schemaa=get-vbrjob -name "Backup HyperV" | Get-VBRJobObject | select-object Name,ApproxSizeString,@{n='Backup Schema';e={'1'}}
$schemab=get-vbrjob -name "Backup ESX" | Get-VBRJobObject | select-object Name,ApproxSizeString,@{n='Backup Schema';e={'1'}}
$schemac=get-vbrjob -name "Backup HyperV Schema 2" | Get-VBRJobObject | select-object Name,ApproxSizeString,@{n='Backup Schema';e={'2'}}
$schemad=get-vbrjob -name "Backup ESX Schema 2" | Get-VBRJobObject | select-object Name,ApproxSizeString,@{n='Backup Schema';e={'2'}}
$schemae=get-vbrjob -name "Backup HyperV Belnet" | Get-VBRJobObject | select-object Name,ApproxSizeString,@{n='Backup Schema';e={'3'}}
$schemaf=get-vbrjob -name "Backup ESX Belnet" | Get-VBRJobObject | select-object Name,ApproxSizeString,@{n='Backup Schema';e={'3'}}
$schemaz=$schemaa+$schemab+$schemac+$schemad+$schemae+$schemaf|sort-object -property "Name"
$schemaz| Export-Csv -force -Path "$DesktopPath\Veeam VM list backuped.txt" -Delimiter ';' -NoTypeInformation

Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests