I am attempting to generate a report from the NIC Teaming script but given the following code will I have to create and Excel object and define it's elements?
The Export-Csv option is not working as I expect it to in this case. Thank you for your assistance. The code follows:
($VMHost in Get-VMHost){
Foreach ($vSwitch in ($VMHost |Get-VirtualSwitch )){
$NicTeaming = Get-NicTeamingPolicy -VirtualSwitch $vSwitch
$obj = new-object psobject
$obj |Add-Member -membertype NoteProperty -Name Host -value $VMHost
$obj |Add-Member -membertype NoteProperty -Name vSwitch -value $vSwitch
$obj |Add-Member -membertype NoteProperty -Name NumPorts -value $vSwitch.NumPorts
$obj |Add-Member -membertype NoteProperty -Name NumPortsAvailable -value $vSwitch.NumPortsAvailable
$PG = $vSwitch |Get-VirtualPortGroup
If ($PG.Count-gt 1){
$obj |Add-Member -membertype NoteProperty -Name PortGroups -value ([string]::join(‘ ,‘,($PG)))
}
Else {
$obj | Add-Member -membertype NoteProperty -Name PortGroups -value $PG
}
$obj |Add-Member -membertype NoteProperty -Name BeaconInterval -value $NicTeaming.BeaconInterval
$obj |Add-Member -membertype NoteProperty -Name LoadBalancingPolicy -value $NicTeaming.LoadBalancingPolicy
$obj |Add-Member -membertype NoteProperty -Name NetworkFailoverDetectionPolicy -value $NicTeaming.NetworkFailoverDetectionPolicy
$obj |Add-Member -membertype NoteProperty -Name NotifySwitches -value $NicTeaming.NotifySwitches
$obj |Add-Member -membertype NoteProperty -Name FailbackEnabled -value $NicTeaming.FailbackEnabled
If ($NicTeaming.ActiveNic-gt 1){
$obj |Add-Member -membertype NoteProperty -Name ActiveNic -value ([string]::join(‘ ,‘,($NicTeaming.ActiveNic)))
}
Else {
$obj |Add-Member -membertype NoteProperty -Name ActiveNic -value $NicTeaming.ActiveNic
}
If ($NicTeaming.StandbyNic-gt 1){
$obj |Add-Member -membertype NoteProperty -Name StandbyNic -value ([string]::join(‘ ,‘,($NicTeaming.StandbyNic)))
}
Else {
$obj |Add-Member -membertype NoteProperty -Name StandbyNic -value $NicTeaming.StandbyNic
}
If ($NicTeaming.UnusedNic-gt 1){
$obj |Add-Member -membertype NoteProperty -Name UnusedNic -value ([string]::join(‘ ,‘,($NicTeaming.UnusedNic)))
}
Else {
$obj |Add-Member -membertype NoteProperty -Name UnusedNic -value $NicTeaming.UnusedNic
}
$obj |Add-Member -membertype NoteProperty -Name CheckBeacon -value $NicTeaming.CheckBeacon
$obj
$Report += $obj
}
$Report = $Report | Sort-Object VMName
IF ($Report -ne "")
{ $Report | Export-Csv NIC-Teaming.csv }
}
Did you declare $report as an array ?
On the first line put
$report = @()
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I suspect that is because you are trying to export an array with rows that do not have the same layout.
All the rows in the array should have the same properties.
Any error messages ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD,
No error message. The code executes but the expected CSV report is never generated.
Did you declare $report as an array ?
On the first line put
$report = @()
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD,
Thank you very much sir. That was it.
As an aside when is your next book on VM performance due out?
Thank you again and make it a great day.
I'm targeting 2014Q2.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hello Lucd
I am getting following error message when i execute, can you please help me?
Unexpected token 'in' in expression or statement.
At D:\script\switch.ps1:3 char:12
+ ($VMHost in <<<< Get-VMHost){
+ CategoryInfo : ParserError: (in:String) [], ParseException
+ FullyQualifiedErrorId : UnexpectedToken
I suspect there might be a typo in the preceding lines somewhere.
Can you eventually share the script you are using (as a file attachment) ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
This line
($VMHost in Get-VMHost){
should be changed into
foreach($VMHost in Get-VMHost){
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
excellent Luc,, its working now 🙂 thanks for your help