Hi all,
I am making a script that gets all WWN and Mac data from all ESX servers. I got the WWN part, now doing the NiC part.
Currently I have the following:
Connect-VIServer "servername"
$esx = Get-VMHost | Get-View
Write-Host $esx.Name
foreach($pNiC in $esx.Config.Network.Pnic.){
write-Host $pNiC.Device $pNic.Mac
}
(Don't worry about the loop I'll fix that later)
I am able to retrieve most things from the Config.network.pnic object,yet the "$pNic.Mac" does not return any data. My script engine returns:
"Cannot process argument because the value of the argument "obj" is null. Change the value of the argument obj to a non-null value"
I basicly get the error. But I cannot find anything for addional arguments.
Can anyone help me out ?
This should work
$esxarray = Get-VMHost | Sort-Object -property Name | Get-View foreach($esx in $esxarray){ Write-Host $esx.Name foreach($pNiC in $esx.Config.Network.Pnic){ write-Host $pNiC.Device $pNic.Mac } }
The output of Get-VMHost | Get-View is an array of HostSystem objects.
The dot after $esx.Config.Network.Pnic caused an error.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
HI,
Check this post out, the posted script seems to meet your needs
http://teckinfo.blogspot.com/2008/12/detailed-vmware-host-network.html
Regards
Hya,
The ". "is a c/p error I left it after trying to put pnic there. Without the dot I still receive this error.
Using the scirpt mentioned above gives:
Unexpected token 'in' in expression or statement.
At :line:2 char:79
+ $esxarray = Get-VMHost | Sort-Object -property Name | Get-View foreach($esx in <<<< $esxarray){ Write-Host $esx.Name foreach($pNiC in $esx.Config.Network.Pnic){ write-Host $pNiC.Device $pNic.Mac } }
So I went onwith the investigation. I used the script on ESX 3.5 and guess what it works there!
It looks as if you lost the CRs and LFs while copying the script.
This is a known problem with the forum SW and IE, can you try accessing it with FF ?
The VITK 1.5 Release Notes state that ESX 3.0 and VC2 are supported platforms.
So it should work.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I was already accessing it with FF.
Well the script is finished, it is as simple as:
$OutputFile = "<path\filename"
Connect-VIServer "VI-server"
$esxarray = Get-VMHost | Sort Name | Get-View
foreach($esx in $esxarray){
$strOutput = $esx.Name
$strOutput | Out-File $Outputfile -Append
foreach($hba in $esx.Config.StorageDevice.HostBusAdapter){
if($hba.GetType().Name -eq "HostFibreChannelHba"){
$wwn = $hba.PortWorldWideName
$wwnhex = "{0:x}" -f $wwn
$strOutput = $hba.Device + " " + $wwnhex
$strOutput | Out-File $Outputfile -Append
}
}
foreach($pNiC in $esx.Config.Network.Pnic){
$strOutput = $pNiC.Device + " " + $pNic.Mac
$strOutput | Out-File $Outputfile -Append
}
}
This gives me all the data I need(Although I need to sort vmnics yet). Thanks for all the help!