Hi Luc,
could you suggest how to get proper output on console using following script.below works fine but even with join operator output is not fully displayed .
$cluster=read-host -Prompt "cluster name"
foreach($esxi in (get-vmhost -Location $cluster))
{
$esxi_name = get-vmhost $esxi
$esxi_name|select name,model,@{N='pNIC';E={(Get-VMHostNetworkAdapter -Physical -VMHost $_).Name -join '|'}},@{N = 'linkspeed';E={$spec=Get-VMHostNetworkAdapter -VMHost $_
$spec.extensiondata.linkspeed.speedMb -join '|'
}}
getting following output name is not shown here .
is the above method not sufficient enough for larger numbers .do we need to use add-psobject method??
You are of course limited by the linesize on the screen, but you could do something like this
$cluster=read-host -Prompt "cluster name"
Get-Cluster -Name $cluster | Get-VMHost |
ForEach-Object -Process {
$obj = [ordered]@{
Name = $_.Name
Model = $_.Model
}
Get-VMHostNetworkAdapter -VMHost $_ -Physical | %{
$obj.Add($_.DeviceName,$_.BitRatePerSec)
}
New-Object PSObject -Property $obj
} | Format-Table -AutoSize
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
You are of course limited by the linesize on the screen, but you could do something like this
$cluster=read-host -Prompt "cluster name"
Get-Cluster -Name $cluster | Get-VMHost |
ForEach-Object -Process {
$obj = [ordered]@{
Name = $_.Name
Model = $_.Model
}
Get-VMHostNetworkAdapter -VMHost $_ -Physical | %{
$obj.Add($_.DeviceName,$_.BitRatePerSec)
}
New-Object PSObject -Property $obj
} | Format-Table -AutoSize
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
it works but the one with dell model has 8 pnics and this code shows only 4.
so i did following but pnic output is still not fully displayed .is it not possible to do something on powershell screen size to accomadate maximum.
$cluster=read-host -Prompt "cluster name"
foreach($esxi in (get-vmhost -Location $cluster))
{
$esxi_name = get-vmhost $esxi
$esxi_name|select name,model,@{N='pNIC';E={(Get-VMHostNetworkAdapter -Physical -VMHost $_).Name -join '|' }}
foreach($pnic in (Get-VMHostNetworkAdapter -VMHost $esxi_name))
{
$pnic.extensiondata.linkspeed.speedMb
}}
Like I already said, it all depends on the width of the console.
When I run my script for ESXi nodes with 8 pNIC, I get it all on one screen.
You could try make the console screen wider, or perhaps make the font size smaller.
But you really can't get more than 80 characters on a line that is 80 characters wide :smileygrin:
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
i am checking this
if you could tell me why below code is not correct specially orange line .
$cluster=read-host -Prompt "cluster name"
foreach($esxi in (get-vmhost -Location $cluster))
{
$esxi_name = get-vmhost $esxi
$esxi_name|select name,model,@{N='pNIC';E={(Get-VMHostNetworkAdapter -Physical -VMHost $_).Name -join '|' | %{$_.extensiondata.linkspeed.speedMb} }}
we are strating with $esxi_name so after this whatever pipeline we will use it will have esxi info stored as $_ and that will be continue till last pipe in expression .
can the above code works by using pipeline variable
You are 'piping' a string ((Get-VMHostNetworkAdapter -Physical -VMHost $_).Name -join '|') to the ForEach loop.
In the loop your are refering (with $_) to the string, not the pNIC object.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi Luc,
i tried various ways to fit the output but not getting the desired result .
so i thought of using following way to output file to either .text ot .csv .is there any modification we can do while outputting report .iam referring to orange line.
$report = @()
foreach($esxi in (get-vmhost -Location 'mycluster'))
{
$esxi_name =Get-VMHost $esxi
$pnic=Get-VMHostNetworkAdapter -Physical -VMHost $esxi_name
foreach($pn in $pnic)
{
$speed=$pn.extensiondata.linkspeed.speedMb
$output = New-Object -TypeName PSObject
$output|Add-Member -MemberType NoteProperty -Name 'esxiname' -Value $esxi_name.name
$output|Add-Member -MemberType NoteProperty -Name 'physicalnics' -Value $pnic.name
$output|Add-Member -MemberType NoteProperty -Name 'spped' -Value $speed
$report += $output
}
}
$report |Out-File nics_speed.txt
The Physicalnics property should perhaps the name of the specific pNIC, not all pNIC names?
The speed is directly available, no need to go into the ExtensionData.
Do you mean like this with the CSV?
$report = @()
foreach($esxi in (Get-VMHost -Location 'MyCluster'))
{
$esxi_name =Get-VMHost $esxi
$pnic=Get-VMHostNetworkAdapter -Physical -VMHost $esxi_name
foreach($pn in $pnic)
{
$output = New-Object -TypeName PSObject
$output|Add-Member -MemberType NoteProperty -Name 'esxiname' -Value $esxi_name.name
$output|Add-Member -MemberType NoteProperty -Name 'physicalnics' -Value $pn.DeviceName
$output|Add-Member -MemberType NoteProperty -Name 'speed' -Value $pn.BitRatePerSec
$report += $output
}
}
$report | Export-Csv -Path .\nics_speed.csv -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
yes i should have chosen $pn instead of $pnic and i found speed is directly available also .
this worked fine as its giving all nics .
is it because of notypeinformation and useculture??
The NotypeInformation switch avoids that a line with type information is added to the CSV.
The UseCulture makes sure that separator for your regional zone is used.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
thanks i tried to run without these .putting $pn instead of $pnic as you pointed earlier provide better readable working output.
appreciate yur help.