Quantcast
Channel: VMware Communities: Message List
Viewing all articles
Browse latest Browse all 229504

Exporting NIC Report

$
0
0

I am not the most crafty with powerCLI and have been using PowerGUI tools to make some and automate them.  I was looking around and there is a script to find NICs that are under 1Gb/s, following that I was able to make some filters and finally produce a report.  But when I take the pre-made script and attempt to make it automatically produce a .csv it fails.  Here is the script:

 

$noConnection = $true

if ($defaultVIServers) {

  foreach ($managedHost in $defaultVIServers) {

  $noConnection = $false

  Get-VMHost -Server $managedHost | ForEach-Object {

  $vmh = Get-View -id $_.id -Server $managedHost

  $vmh.Config.Network.Pnic | ForEach-Object {

  $pNicDevId = $_.Pci

  $key = $_.key

  $PCIDevice = $vmh.Hardware.PciDevice | Where-Object {$_.id -eq $pNicDevId}

  $vSwitch = $vmh.Config.Network.Vswitch | Where-Object {$_.Pnic -contains $key}

  $Duplex = "Half"

  if ($_.LinkSpeed.Duplex -eq $True){$Duplex = "Full"}

  $LinkStatus = "Up"

  if ($_.LinkSpeed -eq $null){

  $LinkStatus = "Down"

  $Duplex = $null

  }

  $LinkConfig = "Auto Negotiate"

  if ($_.Spec.LinkSpeed -ne $null){

  $SpecDuplex = "Half"

  if ($_.Spec.LinkSpeed.Duplex -eq $True){$SpecDuplex = "Full"}

  $LinkConfig = "$($_.Spec.LinkSpeed.SpeedMb, $SpecDuplex)"

  }

  if ($_.LinkSpeed.SpeedMb -ne 1000) {

  $pNic = New-Object PSObject

  $pNic.PSObject.TypeNames.Insert(0,"PhysicalNIC#VmwarePowerPackExtension")

  $pNic `

  | Add-Member -MemberType NoteProperty -Name VMHost -Value $vmh.Name -PassThru `

  | Add-Member -MemberType NoteProperty -Name Device -Value $_.Device -PassThru `

  | Add-Member -MemberType NoteProperty -Name LinkSpeed -Value $_.LinkSpeed.SpeedMb -PassThru `

  | Add-Member -MemberType NoteProperty -Name Duplex -Value $Duplex -PassThru `

  | Add-Member -MemberType NoteProperty -Name "Hardware Vendor" -Value $PCIDevice.VendorName -PassThru `

  | Add-Member -MemberType NoteProperty -Name "Hardware Model" -Value $PCIDevice.DeviceName -PassThru `

  | Add-Member -MemberType NoteProperty -Name Location -Value $_.Pci -PassThru `

  | Add-Member -MemberType NoteProperty -Name Driver -Value $_.Driver -PassThru `

  | Add-Member -MemberType NoteProperty -Name Status -Value $LinkStatus -PassThru `

  | Add-Member -MemberType NoteProperty -Name "Wake On LAN" -Value $_.WakeOnLanSupported -PassThru `

  | Add-Member -MemberType NoteProperty -Name LinkConfig -Value $LinkConfig -PassThru `

  | Add-Member -MemberType NoteProperty -Name "Virtual Switch" -Value $vSwitch.name -PassThru `

  | Add-Member -MemberType NoteProperty -Name MACAddress -Value $_.Mac -PassThru `

  | Add-Member -MemberType NoteProperty -Name key -Value $_.key -PassThru `

  | Add-Member -MemberType NoteProperty -Name Host -Value $managedHost.Name -PassThru

  }

  }

  }

  }

}

if ($noConnection){

  Show-MessageBox -Text 'You must connect to one or more vSphere servers before you can run the Hosts with NIC under 1Gb/s best practice query on those servers. Please click on the ''Managed Hosts'' node, connect to one or more of the vSphere servers you have configured there, and then try again.' -Caption 'Connection not established' -Buttons 'OK' -Icon 'Information' | Out-Null

}

 

 

Any advice would be great!

 

Andy


Viewing all articles
Browse latest Browse all 229504

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>