PowerShell script exchange
Post Reply
Jackjack
Lurker
Posts: 2
Liked: 1 time
Joined: Oct 20, 2020 1:46 pm
Contact:

Mismatching VM folder path with Veeam selected folder

Post by Jackjack »

Hi folks,

I'm actually writing a script that is parsing all the backups, and when there is a folder (not a ressource pool) I'm trying to get the list of Vms inside of it (Veeam 9.5 u4). If I check the "location" part, I can see a path that seems to match with what our VCenter has.

Let's say that from the Veeam point of view, the folder (the .location property from the Get-VBRJobObject cmdlet) is named that way :

VCenter_name/Cluster/Folder_1/Folder_2

I was thinking of getting the same within Vmware using powershell, as the Vms have a "Folder" property, and I can crawl up to the top level using a loop and the .parent property... But I noticed that the parent folder path produces some unexpected result. When I do that, Vmware gives me that kind of result

VCenter_Name/Cluster/Folder_1/vm/Folder2

For that reason, I can't make those 2 informations match. I could be forgetting the "vm " for that path to make it work, but I'll prefer to be able to have the perfect match between those.
Is my method wrong? Is there something I didn't understood?

Many thanks for your help!
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: Mismatching VM folder path with Veeam selected folder

Post by jhoughes » 2 people like this post

You can leverage the 'Find-VBRViEntity' cmdlet with the 'VMsAndTemplates' parameter.

This will list back all of the VMs within your Center environment, and you can use the Path property for the returned VMs to match to your job object location property.

I had an example of this for VM tags added to the cmdlet documentation here (Example #5):
https://helpcenter.veeam.com/docs/backu ... ml?ver=100
Husband, Father, Solutions Architect, Geek Extraordinaire | @DenverVMUG, @AustinVMUG & @ATXPowerShell leader | VMware vExpert | Cisco Champion
evilaedmin
Expert
Posts: 176
Liked: 30 times
Joined: Jul 26, 2018 8:04 pm
Full Name: Eugene V
Contact:

Re: Mismatching VM folder path with Veeam selected folder

Post by evilaedmin » 2 people like this post

Jackjack wrote: Oct 20, 2020 2:11 pm

I was thinking of getting the same within Vmware using powershell, as the Vms have a "Folder" property, and I can crawl up to the top level using a loop and the .parent property... But I noticed that the parent folder path produces some unexpected result. When I do that, Vmware gives me that kind of result

VCenter_Name/Cluster/Folder_1/vm/Folder2
Hi There! Welcome to working with vSphere Web Services API -- whether you know it or not that's what your commandlet is doing. :) And the API has some behaviors that more 'user facing' software like vCenter and Veeam have taken care of for you.

The short answer is that when working with the API, you are going to have some 'default' folders in the hierarchy that you will want to filter out, if you simply want the folders that you see in vcenter with folder icon when viewing 'VMs and Templates'. These are "Datacenters","vm", and "host". These are 'root' folder objects.

Secondly, that 'vm' folder should be at the root of the hierarchy just below the datacenter name. (get-folderpath is our version of the function you created):

Code: Select all

❯ get-vm | get-random | Get-FolderPath

Name Path
---- ----
RDS  MySpecialDatacenterDatacenter\vm\Windows Servers\Production Servers\RDS

So I think there is something not right with your constructing the path.

The longer answer is in this explanation of the vcenter hierarchy: https://code.vmware.com/apis/704/vspher ... tance.html
Jackjack
Lurker
Posts: 2
Liked: 1 time
Joined: Oct 20, 2020 1:46 pm
Contact:

Re: Mismatching VM folder path with Veeam selected folder

Post by Jackjack » 1 person likes this post

So I think there is something not right with your constructing the path.
I wrote that example badly, as I thought it was more or less random, but it just matches what you explained and that I didn't knew :D

Thank you very much both of you for the explanations, I will go with the Find-VBRViEntity and a calculated property to match everything within the same folder
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: Mismatching VM folder path with Veeam selected folder

Post by jhoughes » 1 person likes this post

If you need to get this detail from vSphere itself, you can leverage either Get-View or the ExtensionData to query the SOAP API, or use the CISService cmdlets or Invoke-RestMethod to query the REST API.

The easiest method to understand the issue and see how to query objects properly will probably be in this article on Luc Dekens' blog. He shows it visually and explains the issues, along with providing an inventory script to handle parent folder/object relationships. https://www.lucd.info/2016/06/03/get-in ... e-objects/
Husband, Father, Solutions Architect, Geek Extraordinaire | @DenverVMUG, @AustinVMUG & @ATXPowerShell leader | VMware vExpert | Cisco Champion
Post Reply

Who is online

Users browsing this forum: Baidu [Spider] and 17 guests