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