VMware Cloud Community
orbion
Contributor
Contributor
Jump to solution

esxi output format file

Guys

anyone knows how to create a powershell in order to get the esxi host list on each vcenter and add some words to the output file like you can see the format below???

###    DoNotRemoveOrModifyThisLine

serverName    techspecName

a23veiesx01    techspec_generic_Remediation.csv

a23veiesx02    techspec_generic_Remediation.cs

thx inn advance!!!!

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Just add it to the array after the 1st line.

$report = @()

$report += '###    DoNotRemoveOrModifyThisLine'

$report += 'serverName    techspecName'

Get-VMHost | ForEach-Object -Process {

    $report += "{0} {1}" -f $_.Name,'Some text'

}


$report | Out-File -FilePath .\report.txt


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

View solution in original post

0 Kudos
9 Replies
jpsider
Expert
Expert
Jump to solution

Not quite sure what you are asking for. What is techspecName? and what are you expecting in the .csv files?

0 Kudos
orbion
Contributor
Contributor
Jump to solution

JPsider no matter what is the text close the the esxi hostname....i need to get that format....similar what what i write below

##sometthing

serverName    techspecName

esxihostname          something.csv

i cat get that info using

Get-VMHost | Select name > tests.csv

and i get this

Name                  

----                  

twigaesxi01.tw.ibm.com

twigaesxi02.tw.ibm.com

sgveiesx11            

sgveiesx09            

sgveiesx10          

and i need this on the output file

###    DoNotRemoveOrModifyThisLine

serverName    techspecName

a23veiesx01    techspec_generic_Remediation.csv

a23veiesx02    techspec_generic_Remediation.csv

Great thx for your help

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try something like this.
But note that this is not a valid CSV file.

$report = @()

$report += '###    DoNotRemoveOrModifyThisLine'


Get-VMHost | ForEach-Object -Process {

    $report += "{0} {1}" -f $_.Name,'Some text'

}


$report | Out-File -FilePath .\report.txt


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

0 Kudos
orbion
Contributor
Contributor
Jump to solution

Lucd

this works awesome...you da men..just one more thing...how can i add a new line below this one "###    DoNotRemoveOrModifyThisLine" as you can see below in bold.....

great thx in advance!!!!!!

###    DoNotRemoveOrModifyThisLine

serverName    techspecName

a23veiesx01    techspec_generic_HC.csv

a23veiesx02    techspec_generic_HC.csv

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Just add it to the array after the 1st line.

$report = @()

$report += '###    DoNotRemoveOrModifyThisLine'

$report += 'serverName    techspecName'

Get-VMHost | ForEach-Object -Process {

    $report += "{0} {1}" -f $_.Name,'Some text'

}


$report | Out-File -FilePath .\report.txt


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

0 Kudos
orbion
Contributor
Contributor
Jump to solution

Great Thx Sir..you teach me a lot...as usual

0 Kudos
orbion
Contributor
Contributor
Jump to solution

Lucd

How can i convert this output file in a csv file with TAB as delimiter???

Great Thx

0 Kudos
jpsider
Expert
Expert
Jump to solution

Export-Csv -Delimiter `t -Path 'yourfile.csv' This will put double quotes on everything. If you want to replace those, you will need to add an extra line of Powershell

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try like this

$report = @()

$report += "###`tDoNotRemoveOrModifyThisLine"

$report += "serverName`ttechspecName"


Get-VMHost | ForEach-Object -Process {

    $report += "{0}`t{1}" -f $_.Name,'Some text'

}


$report | Out-File -FilePath .\report.csv

To read this as a CSV you will have to specify the delimiter

Import-Csv -Path .\report.csv -Delimiter "`t"


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

0 Kudos