Hi,
I am having some object related issues when running this script to list physical NIC speeds per NIC per host. The error is:
Method invocation failed because http://System.Management.Automation.PSObject doesn't contain a me
thod named 'op_Addition'.
At line:12 char:23
+ $NicSpReportObj += <<<< $NicSpReportObj
+ CategoryInfo : InvalidOperation: (op_Addition:String) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound
HostName pNIC Speed
esx14.domain.com pnic0 1000
So it will list what I would like to be the last entry in the object but obviously its not adding in the previous info (or wiping it out maybe).
If someone could take a look that would be great,
Thanks,
Dan
Script (also attached):
$VMHosts = Get-VMHost | Sort Name | Get-View
$NicSpReport = @()
$NicSpReportObj = "" | Select-Object HostName, pNIC, Speed
Foreach ($VMHost in $VMHosts)
{
$pnic = 0
Do {
$Speed = $VMHost.Config.Network.Pnic[$pnic].LinkSpeed.SpeedMb
$NicSpReportObj.HostName = $VMHost.Name
$NicSpReportObj.pNIC = "pnic$pnic"
$NicSpReportObj.Speed = $speed
$NicSpReportObj += $NicSpReportObj
$pnic ++}
Until ($pnic -eq ($VMHost.Config.Network.Pnic.Length))
}
$NicSpReport += $NicSpReportObj
$NicSpReport | ft -AutoSize
I did a little rewrite of your script. I hope it will do what you want now:
Get-VMHost | ForEach-Object { $VMHost = $_ $VMHost.Extensiondata.Config.Network.Pnic | ForEach-Object { $NicSpReportObj = "" | Select-Object HostName, pNIC, Speed $NicSpReportObj.HostName = $VMHost.Name $NicSpReportObj.pNIC = $_.Device $NicSpReportObj.Speed = $_.LinkSpeed.SpeedMb $NicSpReportObj } } | Sort-Object -property HostName,pNIC | Format-Table -AutoSize
Regards, Robert
Update: Moved the Sort-Object cmdlet to the end of the script to be able to also sort on the pNIC attribute.
Message was edited by: RvdNieuwendijk
I did a little rewrite of your script. I hope it will do what you want now:
Get-VMHost | ForEach-Object { $VMHost = $_ $VMHost.Extensiondata.Config.Network.Pnic | ForEach-Object { $NicSpReportObj = "" | Select-Object HostName, pNIC, Speed $NicSpReportObj.HostName = $VMHost.Name $NicSpReportObj.pNIC = $_.Device $NicSpReportObj.Speed = $_.LinkSpeed.SpeedMb $NicSpReportObj } } | Sort-Object -property HostName,pNIC | Format-Table -AutoSize
Regards, Robert
Update: Moved the Sort-Object cmdlet to the end of the script to be able to also sort on the pNIC attribute.
Message was edited by: RvdNieuwendijk
Exactly what I was after, better method than I was going down!
Thanks so much for the fast response, help and effort, really appreciated.
Dan
Excellent script, very cool!
Thanks Robbie !
Kind Regards,
AWT