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
}
Is there a space character after .com in your csv file? There is in the error you posted:
There seems to be an extra space at the end of 'esxi1.localhost.com '
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
not sure how it appeared .its fine if i m printing $v
I suspect it already is there in the CSV
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
i dont see any space in the file .i tested one of them with get-vmhost command and it worked fine ..
Check with the Length property if the extra blank is in there.
$v.Length
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
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 .
$v.length issame as sum of individual charecters.
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
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,
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
well its working now with comma ...
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
without comma i cant get the proper output .i m unable to send the .csv file due to security reasons.