Sivaramsharmar
Enthusiast
Enthusiast

Iterating CSV File

Hi All,

We have vCenter 6.7 and not able to execute several commands which are working fine in 6.0.

Below command will fetch the VM Report clusterwise which is working fine in 6.0.

$cl= get-cluster

&{foreach($d in $cl){

Get-Cluster $d | get-vm | select Name,PowerState,vmhost,@{N='VMX Path';E={$_.ExtensionData.Config.Files.VmPathName}},@{N='vCenter';E={$_.uid.split('@:')[1]}} | export-csv .\$d.csv -NoTypeInformation

}}

But above commands are not working in 6.7 version.

So we are using below command to pull the details from vCenter level

get-vm | select Name,PowerState,@{N='ESXi';E={Get-VMHost -Id $_.extensiondata.summary.runtime.host}},@{N='Cluster';E={($_|get-cluster).name}},@{N='VMX Path';E={$_.ExtensionData.Config.Files.VmPathName}},@{N='vCenter';E={$_.uid.split('@:')[1]}} | export-csv .\VM_Inventory.csv -NoTypeInformation

Is there any way that from above VM Inventory CSV File we can able to fetch the details per cluster(CSV) as we are doing it for 6.0 version

Note: We have already tried uninstalling / Re-Installing PowerCLI and tried with different machines as well. But no luck to fetch the details from 6.7 version.

0 Kudos
5 Replies
LucD
Leadership
Leadership

You can run that 1st script like this

Get-Cluster -PipelineVariable cl |

ForEach-Object -Process {

    Get-VM -Location $cl  |

    select Name,PowerState,vmhost,

        @{N='Cluster';E={$cl.Name}},

        @{N='VMX Path';E={$_.ExtensionData.Config.Files.VmPathName}},

        @{N='vCenter';E={$_.uid.split('@:')[1]}}

} | Export-Csv ".\$($cl.Name).csv" -NoTypeInformation -UseCulture


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

0 Kudos
Sivaramsharmar
Enthusiast
Enthusiast

Hi Lucd,

Thanks for the script.

But it's generating .csv file with no data and getting error as below.

Get-VM : 12/24/2019 10:14:08 AM Get-VM      Exception has been thrown by the target of an invocation.

At line:1 char:66

+ ... iable cl | ForEach-Object -Process { Get-VM -Location $cl  |s ...
+                                          ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo      : NotSpecified: (:) [Get-VM], VimException
+ FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM

Could you please help to generate report based on the CSV file.

0 Kudos
LucD
Leadership
Leadership

How did you copy that code?

The lines are mixed, there is a pipeline symbol missing.


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

0 Kudos
Sivaramsharmar
Enthusiast
Enthusiast

I have copied the code into a notepad and brought the code in a single line and pipe symbol is there.

0 Kudos
LucD
Leadership
Leadership

You can't do that in a single line, the <CR><LF> have a purpose.
If you want a single line, replace the <CR><LF> with a semi-column (;)


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

0 Kudos