Hello, TdisalvoOrinoco-
If you want to limit the output to VMs that reside in a particular cluster, you can just start the whole expression with a Get-Cluster, then pipe that to the Get-VM with which you currently start (or use the -Location parameter on Get-VM). So, the first line would be one of:
## get the cluster of interest, and pipe it to Get-VM
Get-ClustermyCluster0 | Get-VM | %{...
## or, get the VMs in the given location (using the -Location parameter)
Get-VM-Location (Get-ClustermyCluster0) | %{...
As for exporting information to CSV, instead of just writing to the console, you would want to get away from the "echo" alias (for Write-Output). Instead, you should output data that can be used by Export-Csv to write the desired CSV file. New-Object is handy for such tasks. Something like:
&{Get-VM-Location (Get-ClustermyCluster0) | %{
$thisVm=$_
## a hashtable for holding properties to be returned
$hshNicInfo= @{}; $hshNicInfo["VMName"] =$thisVm.Name
## for each NIC, build some info with MACAddr, IPInfo, and Network Name
$thisVm.Guest.Nics | % -Begin {$i=0} -Process {
$oThisNicInfo=$_ ## the current NicInfo item
## get the IP info (IPv4 and IPv6 if there, which should be available if VMware Tools are running)
$strIPInfo= ($oThisNicInfo.IpAddress | sort) -join"/"
## add the NicInfo items to the hashtable for later use with New-Object
$hshNicInfo["Nic${i}MACAddr"] =$oThisNicInfo.MacAddress
$hshNicInfo["Nic${i}IPInfo"] =$strIPInfo
$hshNicInfo["Nic${i}NetName"] =$oThisNicInfo.NetworkName
$i++
} ## end foreach-object
## once the hashtable is populated for all NICs, create a new object with the info
New-Object-TypeNamePSObject-Property$hshNicInfo
} ## end foreach-object
## sorting goodness from LucD (of course) at http://communities.vmware.com/message/1769991#1769991
} | sort-Property {(Get-Member-InputObject$_-Name"Nic*").Count} -Descending | Select VMName,Nic* | `
Export-Csv-NoTypeInformation-UseCultureC:\temp\vm_nic_report.csv
This is similar to the script posted in the thread Get-View).
(that post has a bit more info about the sorting needed for proper output, as well as an alternate way to grab the data, using
Anyway, that's a bit more than you might expect to write just starting out with PowerCLI, but does this get the output for which you are looking?