jvm2016
Hot Shot
Hot Shot

import-csv

Hi Luc,

i am getting very weird error .following code works fine till orange

however when i m trying to get vmhost to do further activities it throws error .

esxi1.localhost.com

get-vmhost : 28/10/2020 14:45:32 Get-VMHost VMHost with name

'esxi1.localhost.com ' was not found using the specified filter(s).

At line:6 char:1

+ get-vmhost -Name $v

+ ~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : ObjectNotFound: (:) [Get-VMHost], VimException

    + FullyQualifiedErrorId : Core_OutputHelper_WriteNotFoundError,VMware.VimA

   utomation.ViCore.Cmdlets.Commands.GetVMHost

$esxis=import-csv "C:\Users\jvmishra\Desktop\fileroot.csv"

foreach($e in $esxis)

{

$v=$e.esxiname

$v

get-vmhost -Name $v

}

0 Kudos
14 Replies
scott28tt
VMware Employee
VMware Employee

Is there a space character after .com in your csv file? There is in the error you posted:

Screenshot 2020-10-28 at 15.03.06.png


-------------------------------------------------------------------------------------------------------------------------------------------------------------
VMware Training & Certification blog
0 Kudos
LucD
Leadership
Leadership

There seems to be an extra space at the end of 'esxi1.localhost.com '


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

0 Kudos
jvm2016
Hot Shot
Hot Shot

not sure how it appeared .its fine if i m printing $v

0 Kudos
LucD
Leadership
Leadership

I suspect it already is there in the CSV


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

0 Kudos
jvm2016
Hot Shot
Hot Shot

i dont see any space in the file .i tested one of them with get-vmhost command and it worked fine ..

0 Kudos
LucD
Leadership
Leadership

Check with the Length property if the extra blank is in there.

$v.Length


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

0 Kudos
jvm2016
Hot Shot
Hot Shot

its not there as i m able to use get-vmhost $v when i run individually .

moreover the space seems to come at the end of the fqdn dont know how it happened .

0 Kudos
jvm2016
Hot Shot
Hot Shot

$v.length issame as sum of individual charecters.

0 Kudos
LucD
Leadership
Leadership

I would need to see your CSV and script file (as attachments) to further analyse.

I tested this, and indeed an extra space at the end of the ESXi node name produces the same error.


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

0 Kudos
jvm2016
Hot Shot
Hot Shot

i put comma after each esxi name .it is working now .however i did this multiple times in past and for a single column i did not use coma and it used to work...

esxiname

esxi1.script-infra.local,                           

esxi2.script-infra.local,                              

esxi3.script--infra.local,                              

0 Kudos
LucD
Leadership
Leadership

I'm still pretty sure there was some sort of whitespace (blank, tab ...) at the end of one or more lines in your CSV.

By placing the comma at the end, you have a visual confirmation that there is no trailing blank on a row.


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

0 Kudos
jvm2016
Hot Shot
Hot Shot

well its working now with comma ...

0 Kudos
LucD
Leadership
Leadership

I'm pretty sure you fixed the issue in the CSV by adding the useless comma.

As a test, remove the comma and test again.


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

0 Kudos
jvm2016
Hot Shot
Hot Shot

without comma i cant get the proper output .i m unable to send the .csv file due to security reasons.

0 Kudos