PowerShell script exchange
Post Reply
Talom
Enthusiast
Posts: 43
Liked: 6 times
Joined: Oct 21, 2014 7:56 am
Contact:

Detail Report about all VMs - Performance Issue

Post by Talom » 1 person likes this post

Hey,
i wrote this script a few years ago and it worked fine. But if you execute this script against a bigger Veeam server with about 1000 VMs or more it takes longer than 2 or 3 hours.
I know "Find-VBRObject" is deprecated but i like the informations about RAM, Connection State, Power State etc. which i don't receive if i am using" Find-VBRViEntity".

Does anyone know, how i can get the same information faster?

Code: Select all

try {
    write-host "Starting Veeam Query for DOC"
    Add-PSSnapin -Name VeeamPSSnapIn #-ErrorAction SilentlyContinue
    write-host "Veeam snapin added"
    
    ###############################################################################
    # CSV-Targetfile
    ###############################################################################
	if (!$args[0]) {
        write-host "CSV target file expected"
        exit 4
    }
    $csvFile = $args[0]
    
    write-host "Write data to file $csvFile"
    
    
    ###############################################################################
    # Query VMs and write to CSV
    ###############################################################################

    $list = @()
	 $vmobjs = Get-VBRServer | Where-Object { $_.Type -eq "ESXi" } | Find-VBRObject | Where-Object {$_.Type -eq "VirtualMachine"}
	 $list += $vmobjs


	$list = $list| select -uniq
	
	foreach ($node in $list) {
        $dcName = $node.FindParent("Datacenter").Name
        $node | Add-Member -MemberType NoteProperty -Name "DataCenterName" -Value $dcName
    	$node | Add-Member -MemberType NoteProperty -Name "HostName" -Value $node.Host.Name -Force
	}
	

	$list | Select-Object Name, PowerState, Uuid, ResourcePool, VmFolder, VmFolderName, IsTemplate, ConnectionState, ChangeTracking, FaultTolerance,ConfigVersion,MemoryInMB,CurrentSnapshotRef,Capacity,RealVmSize,RootSnapshot,Type,Ref,Id,Path,Parent, AnnotationNotes, HostName, DataCenterName | Export-Csv $csvFile -NoTypeInformation -Encoding UTF8

}
catch [System.Exception] {
    write-output $_
    write-output "Error running script"
    exit 8
}
exit 0
BACKUP EAGLE® Developer
tsightler
VP, Product Management
Posts: 6035
Liked: 2860 times
Joined: Jun 05, 2009 12:57 pm
Full Name: Tom Sightler
Contact:

Re: Detail Report about all VMs - Performance Issue

Post by tsightler »

A you note, Find-VBRObject is deprecated, and what this means is that it shouldn't be used any more and it doesn't receive much (any?) testing. It's actually pretty broken at this point (it was always somewhat broken), for example, every run just returns every object, regardless if you tell it a specific server or not so in a large environment your current code will end up with 10's of thousands of objects (or more) in $list and will be time consuming. Even in my lab with 10 hosts it contains almost 1400 objects!

Since your report doesn't appear to have anything VMware specific in it, you might consider just using VMware vPower CLI instead.

As an absolute hack, you could probably just change the following line:

Code: Select all

$vmobjs = Get-VBRServer | Where-Object { $_.Type -eq "ESXi" } | Find-VBRObject | Where-Object {$_.Type -eq "VirtualMachine"}
to

Code: Select all

$vmobjs = Find-VBRObject | Where-Object {$_.Type -eq "VirtualMachine"}
So you only call Find-VBRObject once for the entire environment instead of once for each ESXi host.
Talom
Enthusiast
Posts: 43
Liked: 6 times
Joined: Oct 21, 2014 7:56 am
Contact:

Re: Detail Report about all VMs - Performance Issue

Post by Talom »

I am not sure, if i can use vPower CLI on all Veeam Servers, but i will check that. Maybe it's my only chance.

Unfortunately it's not possible to execute your code, because of a missing parameter (Server).
As i remember my tests in the past, the runtime of the Cmdlet with all servers returns more results than an execution with one server, even after i made it unique. (Some replicas were missed...)
BACKUP EAGLE® Developer
tsightler
VP, Product Management
Posts: 6035
Liked: 2860 times
Joined: Jun 05, 2009 12:57 pm
Full Name: Tom Sightler
Contact:

Re: Detail Report about all VMs - Performance Issue

Post by tsightler »

For me, Find-VBRObject resturns the exact same 226 objects in my lab no matter what server I specify, I can choose any ESXi host, or the vCenter, it's always the same 226 objects. I'm sure it didn't work this way in the past, I think it's just that this command isn't very functional in recent versions because it's deprecated and not being updated anymore to keep up with internal code changes.
albertwt
Veteran
Posts: 942
Liked: 53 times
Joined: Nov 05, 2009 12:24 pm
Location: Sydney, NSW
Contact:

Re: Detail Report about all VMs - Performance Issue

Post by albertwt »

Is there any update on this script for Veeam Backup v9.5 ?
--
/* Veeam software enthusiast user & supporter ! */
veremin
Product Manager
Posts: 20415
Liked: 2302 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Detail Report about all VMs - Performance Issue

Post by veremin »

Have you tried to run it against 9.5 environment? Based on the previous responses and post time, it should work fine with VB&R 9.5. Thanks.
Talom
Enthusiast
Posts: 43
Liked: 6 times
Joined: Oct 21, 2014 7:56 am
Contact:

Re: Detail Report about all VMs - Performance Issue

Post by Talom »

One year later ;)

I'm switching to Find-VBRViEntity. It's ok that i don't get information about the RAM or the connection state.

But... I need the annotation notes which i had from VBRObject. Does anyone have any advice on how I can get the information about it? Maybe with a second command to extend the Vm informations.

Here is the current script, which has a few empty columns now but i didn't want to modify the CSV structure.

Code: Select all

try {
    write-host "Starting Veeam Query Servers for DOC"
    Add-PSSnapin -Name VeeamPSSnapIn #-ErrorAction SilentlyContinue
    write-host "Veeam snapin added"
    
    ###############################################################################
    # CSV-Targetfile
    ###############################################################################
 if (!$args[0]) {
        write-host "CSV target file expected"
        exit 4
    }
    $csvFile = $args[0]
   
    write-host "Write data to file $csvFile"
    
    
    ###############################################################################
    # Query VMs and wirte to CSV
    ###############################################################################

    $vmobjs = Find-VBRViEntity | Where-Object {$_.Type -eq "Vm"}

    $vmobjs | Select-Object Name, PowerState, Uuid, ResourcePool, VmFolder, VmFolderName, IsTemplate, ConnectionState, ChangeTracking, FaultTolerancyType,ConfigVersion,MemoryInMB,CurrentSnapshotRef,ProvisionedSize,UsedSize,RootSnapshot,Type,Reference,Id,Path,Parent,AnnotationNotes,VmHostName,DataCenterName | Export-Csv $csvFile -NoTypeInformation -Encoding UTF8

}
catch [System.Exception] {
    write-output $_
    write-output "Error running script"
    exit 8
}
exit 0
BACKUP EAGLE® Developer
Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests