Highlighted
Contributor
Contributor

get-vmhost will not accept string object?

Jump to solution

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?

err.jpg

Many thanks

0 Kudos
1 Solution

Accepted Solutions
Highlighted
User Moderator
User Moderator

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


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

View solution in original post

0 Kudos
6 Replies
Highlighted
User Moderator
User Moderator

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


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

0 Kudos
Highlighted
Contributor
Contributor

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

0 Kudos
Highlighted
User Moderator
User Moderator

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


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

0 Kudos
Highlighted
Contributor
Contributor

Humble apologies,

I have now attached the correct script

0 Kudos
Highlighted
User Moderator
User Moderator

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


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

View solution in original post

0 Kudos
Highlighted
Contributor
Contributor

Thanks LucD

That was what I needed

0 Kudos