VMware Cloud Community
BaskervilleByte
Contributor
Contributor
Jump to solution

get-vmhost will not accept string object?

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

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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

Reply
0 Kudos
6 Replies
LucD
Leadership
Leadership
Jump to solution

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

Reply
0 Kudos
BaskervilleByte
Contributor
Contributor
Jump to solution

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

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

Reply
0 Kudos
BaskervilleByte
Contributor
Contributor
Jump to solution

Humble apologies,

I have now attached the correct script

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

Reply
0 Kudos
BaskervilleByte
Contributor
Contributor
Jump to solution

Thanks LucD

That was what I needed

Reply
0 Kudos