Automation

 View Only
  • 1.  Comparison of VM-Folder-ID and Folder-ID

    Posted Jan 10, 2015 10:12 AM

    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



  • 2.  RE: Comparison of VM-Folder-ID and Folder-ID

    Posted Jan 10, 2015 10:32 AM

    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



  • 3.  RE: Comparison of VM-Folder-ID and Folder-ID

    Posted Jan 10, 2015 10:43 AM

    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



  • 4.  RE: Comparison of VM-Folder-ID and Folder-ID

    Posted Jan 11, 2015 08:03 AM

    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



  • 5.  RE: Comparison of VM-Folder-ID and Folder-ID

    Posted Jan 10, 2015 12:00 PM

    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é