VMware Cloud Community
chakoe
Enthusiast
Enthusiast

Comparison of VM-Folder-ID and Folder-ID

Hi all,

i would like to compare the Folder-ID of an VM-Parent-Folder and another Folder

If the VM-Folder-ID is equal to FolderID = do nothing

If the VM-folder is not equal to FolderID = do something

I have the following lines:

PS C:\> $VMFolderID

FolderId                                                                                                                           

--------                                                                                                                           

Folder-group-v54375                                                                                                                

PS C:\> $FolderID

Id                                                                                                                                 

--                                                                                                                                 

Folder-group-v54375                                                                                                                

PS C:\> $VMFolderID -eq $FolderID

False

What´s going wrong here?

Thanks in advance

Chakoe

Reply
0 Kudos
4 Replies
kunaludapi
Expert
Expert

try something like this. Change values in red., and check if you are getting correct values.

$Folderid = (Get-folder vm).ExtensionData.moref.value

$VmfolderID = (Get-vm test001).FolderId

$folderid -eq $vmfolderid

--------------------------------------------------------------- Kunal Udapi Sr. System Architect (Virtualization, Networking And Storage) http://vcloud-lab.com http://kunaludapi.blogspot.com VMWare vExpert 2014, 2015, 2016 If you found this or other information useful, please consider awarding points for "Correct" or "Helpful".
Reply
0 Kudos
chakoe
Enthusiast
Enthusiast

Hi,

it went into the right direction, but now the values differentiate:

PS C:\> $VMFolderID -eq  $FolderID

False

PS C:\> $VMFolderID

Folder-group-v54375

PS C:\> $FolderID

group-v54375

Reply
0 Kudos
a_p_
Leadership
Leadership

I have the following lines:

PS C:\> $VMFolderID

FolderId                                                                                                                           

--------                                                                                                                           

Folder-group-v54375                                                                                                                

  

PS C:\> $FolderID

Id                                                                                                                                 

--                                                                                                                                 

Folder-group-v54375                                                                                                                

  

PS C:\> $VMFolderID -eq $FolderID

False

What´s going wrong here?

You are comparing objects rather than variables/values. How about s.th. like $VMFolderID.FolderId -eq $FolderID.Id?

André

Reply
0 Kudos
LucD
Leadership
Leadership

It looks as if you retrieved those values with a Select-Object cmdlet.

In that case you will get 2 object, where each of these objects stores the value under a different propertyname (Id and FolderId).

That's why the comparison returns $false.

You should compare the value of these properties, that will return $true.

This shows the difference.

$vm = Get-VM -Name MyVM

$folder = Get-Folder -Name MyFolder

$t1 = $vm | Select FolderId

$t2 = $folder | Select Id

# Returns false

$t1 -eq $t2

# Returns true

$vm.FolderId -eq $folder.Id


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