How can I export the output to .csv
foreach($cluster in Get-Cluster){
foreach($esx in (Get-VMHost -Location $cluster)) {
$esxcli = Get-EsxCli -VMHost $esx
$esxcli.storage.vmfs.extent.list() | %{
$esxcli.storage.core.path.list($_.DeviceName) |
where{$_.Transport -eq 'fc'} | select -first 1 | %{
New-Object PSObject -Property @{
#VC = $vc
Cluster = $cluster.Name
VMHost = $esx.Name
Datastore = $_.DeviceDisplayName
LUN_ID = $_.LUN
#SIOC = (Get-View -ViewType Datastore -Property 'IormConfiguration.Enabled' -Filter @{'Name'="^$($_.DeviceDisplayName)$"}).IormConfiguration.Enabled
}
}
}
}
}
A ForEach doesn't place anything in the pipeline, so you have to capture the output, which you can then pipe to Export-Csv.
For example like this
$report = foreach($cluster in Get-Cluster){
foreach($esx in (Get-VMHost -Location $cluster)) {
$esxcli = Get-EsxCli -VMHost $esx
$esxcli.storage.vmfs.extent.list() | %{
$esxcli.storage.core.path.list($_.DeviceName) |
where{$_.Transport -eq 'fc'} | select -first 1 | %{
New-Object PSObject -Property @{
#VC = $vc
Cluster = $cluster.Name
VMHost = $esx.Name
Datastore = $_.DeviceDisplayName
LUN_ID = $_.LUN
#SIOC = (Get-View -ViewType Datastore -Property 'IormConfiguration.Enabled' -Filter @{'Name'="^$($_.DeviceDisplayName)$"}).IormConfiguration.Enabled
}
}
}
}
}
$report | Export-Csv .\report.csv -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
A ForEach doesn't place anything in the pipeline, so you have to capture the output, which you can then pipe to Export-Csv.
For example like this
$report = foreach($cluster in Get-Cluster){
foreach($esx in (Get-VMHost -Location $cluster)) {
$esxcli = Get-EsxCli -VMHost $esx
$esxcli.storage.vmfs.extent.list() | %{
$esxcli.storage.core.path.list($_.DeviceName) |
where{$_.Transport -eq 'fc'} | select -first 1 | %{
New-Object PSObject -Property @{
#VC = $vc
Cluster = $cluster.Name
VMHost = $esx.Name
Datastore = $_.DeviceDisplayName
LUN_ID = $_.LUN
#SIOC = (Get-View -ViewType Datastore -Property 'IormConfiguration.Enabled' -Filter @{'Name'="^$($_.DeviceDisplayName)$"}).IormConfiguration.Enabled
}
}
}
}
}
$report | Export-Csv .\report.csv -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thank you very much