VMware Cloud Community
fladjova
Contributor
Contributor
Jump to solution

issue with get-folderbypath

Hello LucD many thanks for your help last time.

Now,  i'm having some strange issue with the  function get-folderbypath you created.

With some folder it find 4 times the object i try to search...

here is how it's look like :

DC2

     Discovered virtual machine

     FolderVM-Test

          Fold2

               test

          test

If i ran get-folderbypath -path DC2/foldervm-test/fold2/test it's working fine giving me one folder.

but if i ran get-folderbypath -path DC2/FolderVM-Test/test  it's giving me 4 folder test as output.

And if i try get-folderbypath -path DC2/test (which doesn't not exist) once again it found 4 test folder...

Have you got some suggestions?

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Can you run it with the attached version?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
16 Replies
LucD
Leadership
Leadership
Jump to solution

Yes, that was a bug.
Try with the attached new version of the function


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
fladjova
Contributor
Contributor
Jump to solution

It's working fine Smiley Happy

Many thanks again LucD !!

0 Kudos
LucD
Leadership
Leadership
Jump to solution

I'll update the post.
Thanks for bringing that to my attention.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
fladjova
Contributor
Contributor
Jump to solution

Sorry to bother you again. After a few days i have tested this function on our production vcenter and it does not work anymore... as on our lab vcenter.

I'm a bit confuse.

On the corrected script if remove the -norecusion on the ligne :

          $root = Get-Inventory -Name $_ -Location $root -NoRecursion -Server $vc

It does like older function listing all the folder with the same name.

If  i use the -norecusion it returns nothing. So i removed the erroraction and the error message is :

Get-Inventory : 12/08/2020 11:40:30 Get-Inventory Inventory with name 'VMware' was not found using the specified

So at this time the script we use to move vm is using the old function and so VMs who below to a folder with multiples location will be move by hand.

That's strange Smiley Sad

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Could you show me a sample layout of the folders where it fails?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
fladjova
Contributor
Contributor
Jump to solution

Here is a layout :

we have created a folder a top of our inventory

Folder

DC

Folder1

SameFolder

Folder2

Folder3

SameFolder

But even if looking for Folder1 it is not found using the new script.

And if i use old script by removing -norecusion it is working for uniq folder but not for SameFolder where it found multiple result.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Can you run it with the attached version?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
fladjova
Contributor
Contributor
Jump to solution

Same behavior, nothing returns.

But working on lab vcenter.

is the problem is the root folder which not exist on lab vcenter? i will try to create this folder on lab vcenter to test.

0 Kudos
fladjova
Contributor
Contributor
Jump to solution

it seems that is the problem... Smiley Sad

Not sure why we create this folder, or is it possible to move DC from it.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

I ran that last script against the exact same setup as posted, and it works for me.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
LucD
Leadership
Leadership
Jump to solution

The Path you specify can start with a Folder or a Datacenter, both work in my tests


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
fladjova
Contributor
Contributor
Jump to solution

Not working here with a folder created before DC.

Here is the layout :

vcentername

     Folder

          Datacenter

               Folder1

If i move out Datacenter from Folder it work. As soon as i move back to Folder it doesn't work.

Do you know what are the risk to move out from Folder? We have granted a few permissions on that folder so if we move out DCs we will have to recreate these permissions on DCs.

but is there something else we are missing?

0 Kudos
LucD
Leadership
Leadership
Jump to solution

I replicated your layout

layout.png

and ran the following

Get-FolderByPath -Path 'Folder/DC/Folder1'

Get-FolderByPath -Path 'Folder/DC/Folder1/SameFolder'

Get-FolderByPath -Path 'Folder/DC/Folder2/Folder3/SameFolder'

Get-FolderByPath -Path 'Folder'

And for each of these calls, the correct folder was returned

folders.png


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
fladjova
Contributor
Contributor
Jump to solution

My apologies, i was not giving the folderName  in the path as on previous script (which gave multiple folder) it worked (in a way).

So now with included folder in path it work Smiley Happy

Sorry for the mistake.

Many thanks again for your help.

So maybe the main issue was the missing folder, or the norecursion was also needed?

0 Kudos
LucD
Leadership
Leadership
Jump to solution

The NoRecursion switch is included in the last script I attached.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
fladjova
Contributor
Contributor
Jump to solution

Thanks again, il will mark the last script as correct answer Smiley Happy

have a nice day !

0 Kudos