PowerCLI

 View Only
  • 1.  get-vmhost will not accept string object?

    Posted Oct 12, 2020 02:50 PM

    Hi all,

    I have a very strange issue with powercli command get-vmhost

    If I manually type get-vmhost and the fqdn of said host I can retrieve the details

    However, if I enter the fqdn into a string variable and use that I receive the following error:

    Any ideas as to what is happening?

    Many thanks



  • 2.  RE: get-vmhost will not accept string object?

    Posted Oct 12, 2020 03:22 PM

    I would need to see what and how you assigned the name to the string variable



  • 3.  RE: get-vmhost will not accept string object?

    Posted Oct 12, 2020 03:35 PM

    Hi LucD,

    I attach a copy of my script which is working well to retrieve RDM disks from various vcenter servers, you helped me with a lot of this, many thanks for your earlier help and sorry to pester you again with more

    Basically I sort the required results into an array called $FinalList and then perform some selections on the array to sort the associated hosts and disk devices into their respective vcenter servers

    These variables are then used within a foreach loop where each esxi host info is retrieved using get-vmhost but unfortunately falls over

    I attach the script to demonstrate or provide info, it is at line 84 where the array object of the esxihost is placed into the string variable $STRHost using out-string -inputobject

    $STRHost = Out-String -InputObject $HostSet

    Then I use 'get-vmhost $STRHost' and that is when I receive the error

    $LiveHost = Get-VMHost $STRHost

    $STRHost | get-member = system.string

    I attach my script for your perusal

    Many thanks in advance LucD



  • 4.  RE: get-vmhost will not accept string object?

    Posted Oct 12, 2020 03:49 PM

    Sorry but that script only seems to have 77 lines and I don't find a reference to variable LiveHost.



  • 5.  RE: get-vmhost will not accept string object?

    Posted Oct 12, 2020 04:05 PM

    Humble apologies,

    I have now attached the correct script



  • 6.  RE: get-vmhost will not accept string object?
    Best Answer

    Posted Oct 12, 2020 04:12 PM

    No problem.

    The issue is due to the Select-Object you use.

    An object that is produced by Select-Object is not intended for further assignments.

    Try changing line 81 to the following.
    The ExpandProperty makes sure you will just have the value, not a Select-Object object.

    $HostSets = $finallist | where {$_.vcenterserver -eq $VC} | select -ExpandProperty esxihost -Unique


  • 7.  RE: get-vmhost will not accept string object?

    Posted Oct 13, 2020 07:42 AM

    Thanks LucD

    That was what I needed