I keep receiving input object when adding Export-CSV at the end of the following script. I tried adding a pipe at the beginning and that returns errors as well.
How can I export this script to a csv? The trouble area is in bold
$myvmhosts = Get-VMHost | select Name
foreach($myvmhost in $myvmhosts)
{
Get-VMHostNetworkAdapter -vmkernel -VMHost $myvmhost.Name | select VMhost, Name, Mac, IP | format-table -autosize | Out-String
}
Export-csv C:\info.csv -NoTypeInformation
$myvmhosts = Get-VMHost
foreach($myvmhost in $myvmhosts)
{
Get-VMHostNetworkAdapter -vmkernel -VMHost $myvmhost.Name | select VMhost, Name, Mac, IP | Export-csv C:\info.csv -NoTypeInformation -UseCulture -Append
}
$myvmhosts = Get-VMHost
foreach($myvmhost in $myvmhosts)
{
Get-VMHostNetworkAdapter -vmkernel -VMHost $myvmhost.Name | select VMhost, Name, Mac, IP | Export-csv C:\info.csv -NoTypeInformation -UseCulture -Append
}
You could just do this:
$data = Get-VMHost | Get-VMHostNetworkAdapter -vmkernel | select vmhost, name, mac, ip
$data | convertto-csv -notypeinformation | out-file C:\mycsv.csv
I see I needed to add those arguments. When I added just the export-csv into the loop it returned nothing as a value. I will note to add those values every time I am adding that command into a loop. Thank you
Chris's option is a bit better
You could just do this:
*changed convertto-csv to export-csv
*added -useculture
$data = Get-VMHost | Get-VMHostNetworkAdapter -vmkernel | select vmhost, name, mac, ip
$data | export-csv -notypeinformation -useculture| out-file C:\mycsv.csv