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?
Can you run it with the attached version?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Yes, that was a bug.
Try with the attached new version of the function
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
It's working fine
Many thanks again LucD !!
I'll update the post.
Thanks for bringing that to my attention.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
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
Could you show me a sample layout of the folders where it fails?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
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.
Can you run it with the attached version?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
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.
it seems that is the problem...
Not sure why we create this folder, or is it possible to move DC from it.
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
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
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?
I replicated your layout
and ran the following
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
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
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
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?
The NoRecursion switch is included in the last script I attached.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks again, il will mark the last script as correct answer
have a nice day !