Question

Problem with PS1 script

Asked by: ryder0707

Referring to the accepted solution in http://www.experts-exchange.com/Programming/Languages/Scripting/Q_24728784.html
I'm not able to retrieve value from the following line

$NetworkConfig | Add-Member -Type NoteProperty -Name "PGActiveNic$i" -Value $PortGroupConfig.Spec.Policy.NicTeaming.NicOrder.ActiveNic

I added this line to the part shown in the code below
I'm sure there are values becoz i can see them in powergui, see screenshot

$_ | Get-VirtualPortGroup | %{
          $PortGroup = $_
          $PortGroupConfig = $NetworkSystem.NetworkConfig.PortGroup | ?{ $_.Spec.Name -eq $PortGroup.Name }
 
          $NetworkConfig | Add-Member -Type NoteProperty -Name "PGName$i" -Value $PortGroup.Name
          $NetworkConfig | Add-Member -Type NoteProperty -Name "PGVLanId$i" -Value $PortGroup.VLanId
          $NetworkConfig | Add-Member -Type NoteProperty -Name "PGAllowPromiscuous$i" -Value $PortGroupConfig.Spec.Policy.Security.AllowPromiscuous
          $NetworkConfig | Add-Member -Type NoteProperty -Name "PGMacChanges$i" -Value $PortGroupConfig.Spec.Policy.Security.MacChanges
          $NetworkConfig | Add-Member -Type NoteProperty -Name "PGForgedTransmits$i" -Value $PortGroupConfig.Spec.Policy.Security.ForgedTransmits
          $NetworkConfig | Add-Member -Type NoteProperty -Name "PGActiveNic$i" -Value $PortGroupConfig.Spec.Policy.NicTeaming.NicOrder.ActiveNic
          $i++
        }

                                  
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:

Select allOpen in new window

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-10-01 at 01:31:22ID24776225
Topics

Scripting Languages

,

Powershell

Participating Experts
1
Points
500
Comments
33

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Screenshots?
    Hi, I am writing a piece of software, part of which has been in MSVC++, but most of which is in Delphi. My problem is that I need to get screenshots printed out so that I can include them in the project documentation and in a project presentation. I've tried printscreen, ...
  2. Screenshot--No taskbar
    Hello all, I need to get a screenshot of the desktop...without the taskbar... Thanks
  3. DirectX and Capturing a ScreenShot - 200PTS
    Ok. You know this question had to be asked sometime, and I cannot seem to find anyone else who asked this before... So here it goes: I have created a little program to view an AVI movie. Now, different movies can use different filters (pronounced: co-decs... hehehe). Anyhow,...
  4. Screenshot of Overlay
    Hi, I want to write a vb6 application that makes a screenshot of about 25 or more fps of a certain region on the screen for logging purposes. The pictures taken need to be shown in an imagebox or anything like that where I can do a very fast automatic pixel comparison. (if ...
  5. Take a screenshot
    I know I saw the snippet/code somewhere about how to get a screenshot... I want to provide a URL and have it get a screenshot of that website, and then scale the image, if not possible with the scaling, its oK I got another app that does it. b

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: Chris-DentPosted on 2009-10-01 at 05:21:53ID: 25467858


Looks like ActiveNic is another object, do those 0 and 1 values expand further?

Sticking the value in quotes like this as we had before:

"$($VSwitch.Spec.Policy.NicTeaming.NicOrder.StandbyNic)"

Will (should) concatenate each of the ToString() values to a single string. Or was that failing as well?

Chris

 

by: ryder0707Posted on 2009-10-01 at 05:32:06ID: 25467934

Looks like ActiveNic is another object, do those 0 and 1 values expand further?
No

"$($VSwitch.Spec.Policy.NicTeaming.NicOrder.StandbyNic)"
Do you mean like this?
$($PortGroupConfig.Spec.Policy.NicTeaming.NicOrder.ActiveNic)

 

by: Chris-DentPosted on 2009-10-01 at 05:36:37ID: 25467969


The quotes are necessary, they force conversion of the array values to a string, since you were exporting to a text file if I remember correctly.

Chris

 

by: ryder0707Posted on 2009-10-01 at 05:38:11ID: 25467989

Ok I will try thanks!

 

by: ryder0707Posted on 2009-10-01 at 23:37:22ID: 25475550

Yes it works! How do put "if" condition so that if that variable is null/value is not set or not configured in esx, i will get the string "Inherited" instead
This is because, all port groups by default inherit NIC failover from vSwitch

Thanks!

$Report = Get-Datacenter | %{
 
  $DCName = $_.Name
  $_ | Get-Cluster | %{
 
    $ClusterName = $_
    # Select only the first returned host
    $_ | Get-VMHost | Select-Object -First 1 | %{
 
      $HostID = $_ | Get-View
      $_ | Get-VirtualSwitch | %{
 
        $NetworkConfig = $_ | Select-Object `
          @{n='Datacenter';e={ $DCName }}, `
          @{n='Cluster';e={ $ClusterName }}, `
          @{n='vSwitch';e={ $_.Name }}, `
          @{n='vmNIC';e={ $_.NIC }}, `
          @{n='Ports';e={ $_.NumPorts }}
 
        # Virtual Switch information from the Host
 
        $NetworkSystem = Get-View $HostID.ConfigManager.NetworkSystem
        $VSwitch = $NetworkSystem.NetworkConfig.VSwitch | ?{ $_.Name -eq $NetworkConfig.VSwitch }
 		$NetworkConfig | Add-Member -Type NoteProperty -Name "Host" -Value $Hostid.Name
        $NetworkConfig | Add-Member -Type NoteProperty -Name "AllowPromiscuous" -Value $VSwitch.Spec.Policy.Security.AllowPromiscuous
        $NetworkConfig | Add-Member -Type NoteProperty -Name "MacChanges" -Value $VSwitch.Spec.Policy.Security.MacChanges
        $NetworkConfig | Add-Member -Type NoteProperty -Name "ForgedTransmits" -Value $VSwitch.Spec.Policy.Security.ForgedTransmits
        $NetworkConfig | Add-Member -Type NoteProperty -Name "ActiveNic" -Value "$($VSwitch.Spec.Policy.NicTeaming.NicOrder.ActiveNic)"
        $NetworkConfig | Add-Member -Type NoteProperty -Name "StandbyNic" -Value "$($VSwitch.Spec.Policy.NicTeaming.NicOrder.StandbyNic)"
 
        # Port Group Information from each Virtual Switch       
 
        # A simple ID for the Port Group (used for column / member name)
        $i = 1
 
        $_ | Get-VirtualPortGroup | %{
          $PortGroup = $_
          $PortGroupConfig = $NetworkSystem.NetworkConfig.PortGroup | ?{ $_.Spec.Name -eq $PortGroup.Name }
 
          $NetworkConfig | Add-Member -Type NoteProperty -Name "PGName$i" -Value $PortGroup.Name
          $NetworkConfig | Add-Member -Type NoteProperty -Name "PGVLanId$i" -Value $PortGroup.VLanId
          $NetworkConfig | Add-Member -Type NoteProperty -Name "PGAllowPromiscuous$i" -Value $PortGroupConfig.Spec.Policy.Security.AllowPromiscuous
          $NetworkConfig | Add-Member -Type NoteProperty -Name "PGMacChanges$i" -Value $PortGroupConfig.Spec.Policy.Security.MacChanges
          $NetworkConfig | Add-Member -Type NoteProperty -Name "PGForgedTransmits$i" -Value $PortGroupConfig.Spec.Policy.Security.ForgedTransmits
		  $NetworkConfig | Add-Member -Type NoteProperty -Name "PGActiveNic$i" -Value "$($PortGroupConfig.Spec.Policy.NicTeaming.NicOrder.ActiveNic)"
		  $NetworkConfig | Add-Member -Type NoteProperty -Name "StandbyNic$i" -Value "$($PortGroupConfig.Spec.Policy.NicTeaming.NicOrder.StandbyNic)"
          $i++
        }
 
        $NetworkConfig
      }
    }
  }
}
 
# Fix the object array, ensure all objects within the 
# array contain the same members (required for Format-Table / Export-CSV)
 
$Members = $Report | Select-Object `
  @{n='MemberCount';e={ ($_ | Get-Member).Count }}, `
  @{n='Members';e={ $_.PsObject.Properties | %{ $_.Name } }}
$AllMembers = ($Members | Sort-Object MemberCount -Descending)[0].Members
 
ForEach ($Entry in $Report) {
  ForEach ($Member in $AllMembers)
  {
    If (!($Entry | Get-Member -Name $Member))
    { 
      $Entry | Add-Member -Type NoteProperty -Name $Member -Value ""
    }
  }
}
 
$Report

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:

Select allOpen in new window

 

by: Chris-DentPosted on 2009-10-02 at 03:11:17ID: 25476469


Hopefully this will work.

Chris

$Report = Get-Datacenter | %{
 
  $DCName = $_.Name
  $_ | Get-Cluster | %{
 
    $ClusterName = $_
    # Select only the first returned host
    $_ | Get-VMHost | Select-Object -First 1 | %{
 
      $HostID = $_ | Get-View
      $_ | Get-VirtualSwitch | %{
 
        $NetworkConfig = $_ | Select-Object `
          @{n='Datacenter';e={ $DCName }}, `
          @{n='Cluster';e={ $ClusterName }}, `
          @{n='vSwitch';e={ $_.Name }}, `
          @{n='vmNIC';e={ $_.NIC }}, `
          @{n='Ports';e={ $_.NumPorts }}
 
        # Virtual Switch information from the Host
 
        $NetworkSystem = Get-View $HostID.ConfigManager.NetworkSystem
        $VSwitch = $NetworkSystem.NetworkConfig.VSwitch | ?{ $_.Name -eq $NetworkConfig.VSwitch }
                $NetworkConfig | Add-Member -Type NoteProperty -Name "Host" -Value $Hostid.Name
        $NetworkConfig | Add-Member -Type NoteProperty -Name "AllowPromiscuous" -Value $VSwitch.Spec.Policy.Security.AllowPromiscuous
        $NetworkConfig | Add-Member -Type NoteProperty -Name "MacChanges" -Value $VSwitch.Spec.Policy.Security.MacChanges
        $NetworkConfig | Add-Member -Type NoteProperty -Name "ForgedTransmits" -Value $VSwitch.Spec.Policy.Security.ForgedTransmits
        $NetworkConfig | Add-Member -Type NoteProperty -Name "ActiveNic" -Value "$($VSwitch.Spec.Policy.NicTeaming.NicOrder.ActiveNic)"
        $NetworkConfig | Add-Member -Type NoteProperty -Name "StandbyNic" -Value "$($VSwitch.Spec.Policy.NicTeaming.NicOrder.StandbyNic)"
 
        # Port Group Information from each Virtual Switch       
 
        # A simple ID for the Port Group (used for column / member name)
        $i = 1
 
        $_ | Get-VirtualPortGroup | %{
          $PortGroup = $_
          $PortGroupConfig = $NetworkSystem.NetworkConfig.PortGroup | ?{ $_.Spec.Name -eq $PortGroup.Name }
 
          $NetworkConfig | Add-Member -Type NoteProperty -Name "PGName$i" -Value $PortGroup.Name
          $NetworkConfig | Add-Member -Type NoteProperty -Name "PGVLanId$i" -Value $PortGroup.VLanId
          $NetworkConfig | Add-Member -Type NoteProperty -Name "PGAllowPromiscuous$i" -Value $PortGroupConfig.Spec.Policy.Security.AllowPromiscuous
          $NetworkConfig | Add-Member -Type NoteProperty -Name "PGMacChanges$i" -Value $PortGroupConfig.Spec.Policy.Security.MacChanges
          $NetworkConfig | Add-Member -Type NoteProperty -Name "PGForgedTransmits$i" -Value $PortGroupConfig.Spec.Policy.Security.ForgedTransmits
 
          If ($PortGroupConfig.Spec.Policy.NicTeaming.NicOrder.ActiveNic -eq $Null) {
            $NetworkConfig | Add-Member -Type NoteProperty -Name "PGActiveNic$i" -Value "Inherited"
          } Else {
            $NetworkConfig | Add-Member -Type NoteProperty -Name "PGActiveNic$i" `
              -Value "$($PortGroupConfig.Spec.Policy.NicTeaming.NicOrder.ActiveNic)"
          }
 
          If ($PostGroup.Config.Spec.Policy.NicTeaming.NicOrder.StandbyNic -eq $Null) {
            $NetworkConfig | Add-Member -Type NoteProperty -Name "StandbyNic$i" -Value "Inherited"
          } Else {
            $NetworkConfig | Add-Member -Type NoteProperty -Name "StandbyNic$i" `
              -Value "$($PortGroupConfig.Spec.Policy.NicTeaming.NicOrder.StandbyNic)"
          }
          $i++
        }
 
        $NetworkConfig
      }
    }
  }
}
 
# Fix the object array, ensure all objects within the 
# array contain the same members (required for Format-Table / Export-CSV)
 
$Members = $Report | Select-Object `
  @{n='MemberCount';e={ ($_ | Get-Member).Count }}, `
  @{n='Members';e={ $_.PsObject.Properties | %{ $_.Name } }}
$AllMembers = ($Members | Sort-Object MemberCount -Descending)[0].Members
 
ForEach ($Entry in $Report) {
  ForEach ($Member in $AllMembers)
  {
    If (!($Entry | Get-Member -Name $Member))
    { 
      $Entry | Add-Member -Type NoteProperty -Name $Member -Value ""
    }
  }
}
 
$Report

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:

Select allOpen in new window

 

by: ryder0707Posted on 2009-10-02 at 03:53:57ID: 25476630

I'm expecting this

vSwitch              : vSwitch0
PGActiveNic.1        : vmnic2 vmnic3
StandbyNic.1         : vmnic0 vmnic1
PGActiveNic.2        : vmnic0 vmnic1
StandbyNic.2         : vmnic2 vmnic3

vSwitch              : vSwitch1
PGActiveNic.1        : Inherited
StandbyNic.1         : Inherited

But i got this

vSwitch              : vSwitch0
PGActiveNic1         : vmnic2 vmnic3
StandbyNic1          : Inherited
PGActiveNic2         : vmnic0 vmnic1
StandbyNic2          : Inherited

vSwitch              : vSwitch1
PGActiveNic1         : Inherited
StandbyNic1          : Inherited

 

by: Chris-DentPosted on 2009-10-02 at 05:13:24ID: 25477101


Hmm it doesn't look very reliable. Lets try this one? I doubt it will work any better ;)

Chris

$Report = Get-Datacenter | %{
 
  $DCName = $_.Name
  $_ | Get-Cluster | %{
 
    $ClusterName = $_
    # Select only the first returned host
    $_ | Get-VMHost | Select-Object -First 1 | %{
 
      $HostID = $_ | Get-View
      $_ | Get-VirtualSwitch | %{
 
        $NetworkConfig = $_ | Select-Object `
          @{n='Datacenter';e={ $DCName }}, `
          @{n='Cluster';e={ $ClusterName }}, `
          @{n='vSwitch';e={ $_.Name }}, `
          @{n='vmNIC';e={ $_.NIC }}, `
          @{n='Ports';e={ $_.NumPorts }}
 
        # Virtual Switch information from the Host
 
        $NetworkSystem = Get-View $HostID.ConfigManager.NetworkSystem
        $VSwitch = $NetworkSystem.NetworkConfig.VSwitch | ?{ $_.Name -eq $NetworkConfig.VSwitch }
                $NetworkConfig | Add-Member -Type NoteProperty -Name "Host" -Value $Hostid.Name
        $NetworkConfig | Add-Member -Type NoteProperty -Name "AllowPromiscuous" -Value $VSwitch.Spec.Policy.Security.AllowPromiscuous
        $NetworkConfig | Add-Member -Type NoteProperty -Name "MacChanges" -Value $VSwitch.Spec.Policy.Security.MacChanges
        $NetworkConfig | Add-Member -Type NoteProperty -Name "ForgedTransmits" -Value $VSwitch.Spec.Policy.Security.ForgedTransmits
        $NetworkConfig | Add-Member -Type NoteProperty -Name "ActiveNic" -Value "$($VSwitch.Spec.Policy.NicTeaming.NicOrder.ActiveNic)"
        $NetworkConfig | Add-Member -Type NoteProperty -Name "StandbyNic" -Value "$($VSwitch.Spec.Policy.NicTeaming.NicOrder.StandbyNic)"
 
        # Port Group Information from each Virtual Switch       
 
        # A simple ID for the Port Group (used for column / member name)
        $i = 1
 
        $_ | Get-VirtualPortGroup | %{
          $PortGroup = $_
          $PortGroupConfig = $NetworkSystem.NetworkConfig.PortGroup | ?{ $_.Spec.Name -eq $PortGroup.Name }
 
          $NetworkConfig | Add-Member -Type NoteProperty -Name "PGName$i" -Value $PortGroup.Name
          $NetworkConfig | Add-Member -Type NoteProperty -Name "PGVLanId$i" -Value $PortGroup.VLanId
          $NetworkConfig | Add-Member -Type NoteProperty -Name "PGAllowPromiscuous$i" -Value $PortGroupConfig.Spec.Policy.Security.AllowPromiscuous
          $NetworkConfig | Add-Member -Type NoteProperty -Name "PGMacChanges$i" -Value $PortGroupConfig.Spec.Policy.Security.MacChanges
          $NetworkConfig | Add-Member -Type NoteProperty -Name "PGForgedTransmits$i" -Value $PortGroupConfig.Spec.Policy.Security.ForgedTransmits
 
          $NetworkConfig | Add-Member -Type NoteProperty -Name "PGActiveNic$i" `
            -Value "$($PortGroupConfig.Spec.Policy.NicTeaming.NicOrder.ActiveNic)"
          If ($NetworkConfig.ActiveNic -eq "") { $NetworkConfig.ActiveNic = "Inherited" }
 
          $NetworkConfig | Add-Member -Type NoteProperty -Name "StandbyNic$i" `
            -Value "$($PortGroupConfig.Spec.Policy.NicTeaming.NicOrder.StandbyNic)"
          If ($NetworkConfig.StandbyNic -eq "") { $NetworkConfig.StandbyNic = "Inherited" }
          }
          $i++
        }
 
        $NetworkConfig
      }
    }
  }
}
 
# Fix the object array, ensure all objects within the 
# array contain the same members (required for Format-Table / Export-CSV)
 
$Members = $Report | Select-Object `
  @{n='MemberCount';e={ ($_ | Get-Member).Count }}, `
  @{n='Members';e={ $_.PsObject.Properties | %{ $_.Name } }}
$AllMembers = ($Members | Sort-Object MemberCount -Descending)[0].Members
 
ForEach ($Entry in $Report) {
  ForEach ($Member in $AllMembers)
  {
    If (!($Entry | Get-Member -Name $Member))
    { 
      $Entry | Add-Member -Type NoteProperty -Name $Member -Value ""
    }
  }
}
 
$Report

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:

Select allOpen in new window

 

by: ryder0707Posted on 2009-10-02 at 05:22:49ID: 25477146

hmmm....not sure what happen...

$NetworkConfig | PipelineBreakpointerE4078E3092DF4dd9A469F3DC0CBB505C(00000000000000002750) | Add-Member -Type NoteProperty -Name "Sta
ndbyNic$i" `
            -Value "$($PortGroupConfig.Spec.Policy.NicTeaming.NicOrder.StandbyNic)"
          If ($NetworkConfig.StandbyNic -eq "") { $NetworkConfig.StandbyNic = "Inherited" }
         
$NetworkConfig | PipelineBreakpointerE4078E3092DF4dd9A469F3DC0CBB505C(00000000000000002750) | Add-Member -Type NoteProperty -Name "Sta
ndbyNic$i" `
            -Value "$($PortGroupConfig.Spec.Policy.NicTeaming.NicOrder.StandbyNic)"
          If ($NetworkConfig.StandbyNic -eq "") { $NetworkConfig.StandbyNic = "Inherited" }
         


Datacenter          : LabDC
Cluster             : myCluster
vSwitch             : vSwitch0
vmNIC               : {vmnic3, vmnic2, vmnic1, vmnic0}
Ports               : 64
Host                : 192.168.88.51
AllowPromiscuous    : False
MacChanges          : True
ForgedTransmits     : True
ActiveNic           : vmnic0 vmnic1 vmnic2 vmnic3
StandbyNic          :
PGName1             : Service Console
PGVLanId1           : 0
PGAllowPromiscuous1 : False
PGMacChanges1       : False
PGForgedTransmits1  : False
PGActiveNic1        : vmnic2 vmnic3
PGName2             : VMkernel
PGVLanId2           : 0
PGAllowPromiscuous2 : False
PGMacChanges2       : False
PGForgedTransmits2  : False
PGActiveNic2        : vmnic0 vmnic1

$NetworkConfig | PipelineBreakpointerE4078E3092DF4dd9A469F3DC0CBB505C(00000000000000002750) | Add-Member -Type NoteProperty -Name "Sta
ndbyNic$i" `
            -Value "$($PortGroupConfig.Spec.Policy.NicTeaming.NicOrder.StandbyNic)"
          If ($NetworkConfig.StandbyNic -eq "") { $NetworkConfig.StandbyNic = "Inherited" }
         
Datacenter          : LabDC
Cluster             : myCluster
vSwitch             : vSwitch1
vmNIC               : {vmnic5, vmnic4}
Ports               : 64
Host                : 192.168.88.51
AllowPromiscuous    : False
MacChanges          : True
ForgedTransmits     : True
ActiveNic           : vmnic4 vmnic5
StandbyNic          :
PGName1             : Virtual Machine Network
PGVLanId1           : 0
PGAllowPromiscuous1 : False
PGMacChanges1       : False
PGForgedTransmits1  : False
PGActiveNic1        :
PGName2             :
PGVLanId2           :
PGAllowPromiscuous2 :
PGMacChanges2       :
PGForgedTransmits2  :
PGActiveNic2        :

 

by: Chris-DentPosted on 2009-10-02 at 05:29:20ID: 25477199


Sorry, I left an errant } in there.

Try again :)

Chris

$Report = Get-Datacenter | %{
 
  $DCName = $_.Name
  $_ | Get-Cluster | %{
 
    $ClusterName = $_
    # Select only the first returned host
    $_ | Get-VMHost | Select-Object -First 1 | %{
 
      $HostID = $_ | Get-View
      $_ | Get-VirtualSwitch | %{
 
        $NetworkConfig = $_ | Select-Object `
          @{n='Datacenter';e={ $DCName }}, `
          @{n='Cluster';e={ $ClusterName }}, `
          @{n='vSwitch';e={ $_.Name }}, `
          @{n='vmNIC';e={ $_.NIC }}, `
          @{n='Ports';e={ $_.NumPorts }}
 
        # Virtual Switch information from the Host
 
        $NetworkSystem = Get-View $HostID.ConfigManager.NetworkSystem
        $VSwitch = $NetworkSystem.NetworkConfig.VSwitch | ?{ $_.Name -eq $NetworkConfig.VSwitch }
                $NetworkConfig | Add-Member -Type NoteProperty -Name "Host" -Value $Hostid.Name
        $NetworkConfig | Add-Member -Type NoteProperty -Name "AllowPromiscuous" -Value $VSwitch.Spec.Policy.Security.AllowPromiscuous
        $NetworkConfig | Add-Member -Type NoteProperty -Name "MacChanges" -Value $VSwitch.Spec.Policy.Security.MacChanges
        $NetworkConfig | Add-Member -Type NoteProperty -Name "ForgedTransmits" -Value $VSwitch.Spec.Policy.Security.ForgedTransmits
        $NetworkConfig | Add-Member -Type NoteProperty -Name "ActiveNic" -Value "$($VSwitch.Spec.Policy.NicTeaming.NicOrder.ActiveNic)"
        $NetworkConfig | Add-Member -Type NoteProperty -Name "StandbyNic" -Value "$($VSwitch.Spec.Policy.NicTeaming.NicOrder.StandbyNic)"
 
        # Port Group Information from each Virtual Switch       
 
        # A simple ID for the Port Group (used for column / member name)
        $i = 1
 
        $_ | Get-VirtualPortGroup | %{
          $PortGroup = $_
          $PortGroupConfig = $NetworkSystem.NetworkConfig.PortGroup | ?{ $_.Spec.Name -eq $PortGroup.Name }
 
          $NetworkConfig | Add-Member -Type NoteProperty -Name "PGName$i" -Value $PortGroup.Name
          $NetworkConfig | Add-Member -Type NoteProperty -Name "PGVLanId$i" -Value $PortGroup.VLanId
          $NetworkConfig | Add-Member -Type NoteProperty -Name "PGAllowPromiscuous$i" -Value $PortGroupConfig.Spec.Policy.Security.AllowPromiscuous
          $NetworkConfig | Add-Member -Type NoteProperty -Name "PGMacChanges$i" -Value $PortGroupConfig.Spec.Policy.Security.MacChanges
          $NetworkConfig | Add-Member -Type NoteProperty -Name "PGForgedTransmits$i" -Value $PortGroupConfig.Spec.Policy.Security.ForgedTransmits
 
          $NetworkConfig | Add-Member -Type NoteProperty -Name "PGActiveNic$i" `
            -Value "$($PortGroupConfig.Spec.Policy.NicTeaming.NicOrder.ActiveNic)"
          If ($NetworkConfig.ActiveNic -eq "") { $NetworkConfig.ActiveNic = "Inherited" }
 
          $NetworkConfig | Add-Member -Type NoteProperty -Name "StandbyNic$i" `
            -Value "$($PortGroupConfig.Spec.Policy.NicTeaming.NicOrder.StandbyNic)"
          If ($NetworkConfig.StandbyNic -eq "") { $NetworkConfig.StandbyNic = "Inherited" }
          $i++
        }
 
        $NetworkConfig
      }
    }
  }
}
 
# Fix the object array, ensure all objects within the 
# array contain the same members (required for Format-Table / Export-CSV)
 
$Members = $Report | Select-Object `
  @{n='MemberCount';e={ ($_ | Get-Member).Count }}, `
  @{n='Members';e={ $_.PsObject.Properties | %{ $_.Name } }}
$AllMembers = ($Members | Sort-Object MemberCount -Descending)[0].Members
 
ForEach ($Entry in $Report) {
  ForEach ($Member in $AllMembers)
  {
    If (!($Entry | Get-Member -Name $Member))
    { 
      $Entry | Add-Member -Type NoteProperty -Name $Member -Value ""
    }
  }
}
 
$Report
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:

Select allOpen in new window

 

by: ryder0707Posted on 2009-10-02 at 05:49:39ID: 25477348

See lines marked with ------>
The string "inherited" is misplaced or missing

Datacenter          : LabDC
Cluster             : myCluster
vSwitch             : vSwitch0
vmNIC               : {vmnic3, vmnic2, vmnic1, vmnic0}
Ports               : 64
Host                : 192.168.88.51
AllowPromiscuous    : False
MacChanges          : True
ForgedTransmits     : True
ActiveNic           : vmnic0 vmnic1 vmnic2 vmnic3
------> StandbyNic          : Inherited
PGName1             : Service Console
PGVLanId1           : 0
PGAllowPromiscuous1 : False
PGMacChanges1       : False
PGForgedTransmits1  : False
PGActiveNic1        : vmnic2 vmnic3
StandbyNic1         : vmnic0 vmnic1
PGName2             : VMkernel
PGVLanId2           : 0
PGAllowPromiscuous2 : False
PGMacChanges2       : False
PGForgedTransmits2  : False
PGActiveNic2        : vmnic0 vmnic1
StandbyNic2         : vmnic2 vmnic3


Datacenter          : LabDC
Cluster             : myCluster
vSwitch             : vSwitch1
vmNIC               : {vmnic5, vmnic4}
Ports               : 64
Host                : 192.168.88.51
AllowPromiscuous    : False
MacChanges          : True
ForgedTransmits     : True
ActiveNic           : vmnic4 vmnic5
------> StandbyNic          : Inherited
PGName1             : Virtual Machine Network
PGVLanId1           : 0
PGAllowPromiscuous1 : False
PGMacChanges1       : False
PGForgedTransmits1  : False
------> PGActiveNic1        :
------> StandbyNic1         :
PGName2             :
PGVLanId2           :
PGAllowPromiscuous2 :
PGMacChanges2       :
PGForgedTransmits2  :
PGActiveNic2        :
StandbyNic2         :

 

by: ryder0707Posted on 2009-10-05 at 01:27:06ID: 25493293

Hi Chris, hoping that you could help me pls

 

by: Chris-DentPosted on 2009-10-05 at 01:36:29ID: 25493336


Sorry dude, got a bit busy.

I don't think we'll be able to do much about it and it might be better going back to the first set-up. Or at least, I don't think I'll be able to do much about it without having something to explore it against.

Chris

 

by: ryder0707Posted on 2009-10-05 at 01:40:15ID: 25493352

hmm...what information you need?

 

by: Chris-DentPosted on 2009-10-05 at 01:51:49ID: 25493412


Not sure, I need to know why it's failing the Null check we created in the first place.

That is, when we got this:

But i got this

vSwitch              : vSwitch0
PGActiveNic1         : vmnic2 vmnic3
StandbyNic1          : Inherited
PGActiveNic2         : vmnic0 vmnic1
StandbyNic2          : Inherited

vSwitch              : vSwitch1
PGActiveNic1         : Inherited
StandbyNic1          : Inherited

I would like to test the values it's returning for StandbyNic1 and 2 to see if they're really Null at that point in the script. I have to assume they are, I can't imagine it lying to us :)

Chris

$Report = Get-Datacenter | %{
 
  $DCName = $_.Name
  $_ | Get-Cluster | %{
 
    $ClusterName = $_
    # Select only the first returned host
    $_ | Get-VMHost | Select-Object -First 1 | %{
 
      $HostID = $_ | Get-View
      $_ | Get-VirtualSwitch | %{
 
        $NetworkConfig = $_ | Select-Object `
          @{n='Datacenter';e={ $DCName }}, `
          @{n='Cluster';e={ $ClusterName }}, `
          @{n='vSwitch';e={ $_.Name }}, `
          @{n='vmNIC';e={ $_.NIC }}, `
          @{n='Ports';e={ $_.NumPorts }}
 
        # Virtual Switch information from the Host
 
        $NetworkSystem = Get-View $HostID.ConfigManager.NetworkSystem
        $VSwitch = $NetworkSystem.NetworkConfig.VSwitch | ?{ $_.Name -eq $NetworkConfig.VSwitch }
                $NetworkConfig | Add-Member -Type NoteProperty -Name "Host" -Value $Hostid.Name
        $NetworkConfig | Add-Member -Type NoteProperty -Name "AllowPromiscuous" -Value $VSwitch.Spec.Policy.Security.AllowPromiscuous
        $NetworkConfig | Add-Member -Type NoteProperty -Name "MacChanges" -Value $VSwitch.Spec.Policy.Security.MacChanges
        $NetworkConfig | Add-Member -Type NoteProperty -Name "ForgedTransmits" -Value $VSwitch.Spec.Policy.Security.ForgedTransmits
        $NetworkConfig | Add-Member -Type NoteProperty -Name "ActiveNic" -Value "$($VSwitch.Spec.Policy.NicTeaming.NicOrder.ActiveNic)"
        $NetworkConfig | Add-Member -Type NoteProperty -Name "StandbyNic" -Value "$($VSwitch.Spec.Policy.NicTeaming.NicOrder.StandbyNic)"
 
        # Port Group Information from each Virtual Switch       
 
        # A simple ID for the Port Group (used for column / member name)
        $i = 1
 
        $_ | Get-VirtualPortGroup | %{
          $PortGroup = $_
          $PortGroupConfig = $NetworkSystem.NetworkConfig.PortGroup | ?{ $_.Spec.Name -eq $PortGroup.Name }
 
          $NetworkConfig | Add-Member -Type NoteProperty -Name "PGName$i" -Value $PortGroup.Name
          $NetworkConfig | Add-Member -Type NoteProperty -Name "PGVLanId$i" -Value $PortGroup.VLanId
          $NetworkConfig | Add-Member -Type NoteProperty -Name "PGAllowPromiscuous$i" -Value $PortGroupConfig.Spec.Policy.Security.AllowPromiscuous
          $NetworkConfig | Add-Member -Type NoteProperty -Name "PGMacChanges$i" -Value $PortGroupConfig.Spec.Policy.Security.MacChanges
          $NetworkConfig | Add-Member -Type NoteProperty -Name "PGForgedTransmits$i" -Value $PortGroupConfig.Spec.Policy.Security.ForgedTransmits
 
          If ($PortGroupConfig.Spec.Policy.NicTeaming.NicOrder.ActiveNic -eq $Null) {
            $NetworkConfig | Add-Member -Type NoteProperty -Name "PGActiveNic$i" -Value "Inherited"
          } Else {
            $NetworkConfig | Add-Member -Type NoteProperty -Name "PGActiveNic$i" `
              -Value "$($PortGroupConfig.Spec.Policy.NicTeaming.NicOrder.ActiveNic)"
          }
 
          If ($PostGroup.Config.Spec.Policy.NicTeaming.NicOrder.StandbyNic -eq $Null) {
            $NetworkConfig | Add-Member -Type NoteProperty -Name "StandbyNic$i" -Value "Inherited"
          } Else {
            $NetworkConfig | Add-Member -Type NoteProperty -Name "StandbyNic$i" `
              -Value "$($PortGroupConfig.Spec.Policy.NicTeaming.NicOrder.StandbyNic)"
          }
          $i++
        }
 
        $NetworkConfig
      }
    }
  }
}
 
# Fix the object array, ensure all objects within the 
# array contain the same members (required for Format-Table / Export-CSV)
 
$Members = $Report | Select-Object `
  @{n='MemberCount';e={ ($_ | Get-Member).Count }}, `
  @{n='Members';e={ $_.PsObject.Properties | %{ $_.Name } }}
$AllMembers = ($Members | Sort-Object MemberCount -Descending)[0].Members
 
ForEach ($Entry in $Report) {
  ForEach ($Member in $AllMembers)
  {
    If (!($Entry | Get-Member -Name $Member))
    { 
      $Entry | Add-Member -Type NoteProperty -Name $Member -Value ""
    }
  }
}
 
$Report
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:

Select allOpen in new window

 

by: ryder0707Posted on 2009-10-05 at 02:34:10ID: 25493594

See output below

Datacenter          : LabDC
Cluster             : myCluster
vSwitch             : vSwitch0
vmNIC               : {vmnic3, vmnic2, vmnic1, vmnic0}
Ports               : 64
Host                : 192.168.88.51
AllowPromiscuous    : False
MacChanges          : True
ForgedTransmits     : True
ActiveNic           : vmnic0 vmnic1 vmnic2 vmnic3
StandbyNic          :
PGName1             : Service Console
PGVLanId1           : 0
PGAllowPromiscuous1 : False
PGMacChanges1       : False
PGForgedTransmits1  : False
PGActiveNic1        : vmnic2 vmnic3
StandbyNic1         : Inherited
PGName2             : VMkernel
PGVLanId2           : 0
PGAllowPromiscuous2 : False
PGMacChanges2       : False
PGForgedTransmits2  : False
PGActiveNic2        : vmnic0 vmnic1
StandbyNic2         : Inherited

Datacenter          : LabDC
Cluster             : myCluster
vSwitch             : vSwitch1
vmNIC               : {vmnic5, vmnic4}
Ports               : 64
Host                : 192.168.88.51
AllowPromiscuous    : False
MacChanges          : True
ForgedTransmits     : True
ActiveNic           : vmnic4 vmnic5
StandbyNic          :
PGName1             : Virtual Machine Network
PGVLanId1           : 0
PGAllowPromiscuous1 : False
PGMacChanges1       : False
PGForgedTransmits1  : False
PGActiveNic1        : Inherited
StandbyNic1         : Inherited
PGName2             :
PGVLanId2           :
PGAllowPromiscuous2 :
PGMacChanges2       :
PGForgedTransmits2  :
PGActiveNic2        :
StandbyNic2         :

 

by: Chris-DentPosted on 2009-10-05 at 02:38:22ID: 25493613


StandbyNic (StandbyNic1, vSwitch0) has to be Null to end up in that state. But you think it should be showing vmnic0 and vmnic1?

It could be an oddity of how the data is presented to us (even if that's a little unlikely), very difficult to say for sure without being able to explore the objects it's using though.

Chris

 

by: ryder0707Posted on 2009-10-05 at 02:58:54ID: 25493714

It is not what i think, it is actually configured at the esx host

 

by: Chris-DentPosted on 2009-10-05 at 03:00:03ID: 25493725


hehe sorry, bad choice of words :) Did it correctly report the adapter usage before we started trying to check for nulls?

Chris

 

by: ryder0707Posted on 2009-10-05 at 03:08:13ID: 25493765

Yes i think so, see output from your previous script, it works fine

Datacenter          : LabDC
Cluster             : myCluster
vSwitch             : vSwitch0
vmNIC               : {vmnic3, vmnic2, vmnic1, vmnic0}
Ports               : 64
Host                : 192.168.88.51
AllowPromiscuous    : False
MacChanges          : True
ForgedTransmits     : True
ActiveNic           : vmnic0 vmnic1 vmnic2 vmnic3
StandbyNic          :
PGName1             : Service Console
PGVLanId1           : 0
PGAllowPromiscuous1 : False
PGMacChanges1       : False
PGForgedTransmits1  : False
PGActiveNic1        : vmnic2 vmnic3
StandbyNic1         : vmnic0 vmnic1
PGName2             : VMkernel
PGVLanId2           : 0
PGAllowPromiscuous2 : False
PGMacChanges2       : False
PGForgedTransmits2  : False
PGActiveNic2        : vmnic0 vmnic1
StandbyNic2         : vmnic2 vmnic3

Datacenter          : LabDC
Cluster             : myCluster
vSwitch             : vSwitch1
vmNIC               : {vmnic5, vmnic4}
Ports               : 64
Host                : 192.168.88.51
AllowPromiscuous    : False
MacChanges          : True
ForgedTransmits     : True
ActiveNic           : vmnic4 vmnic5
StandbyNic          :
PGName1             : Virtual Machine Network
PGVLanId1           : 0
PGAllowPromiscuous1 : False
PGMacChanges1       : False
PGForgedTransmits1  : False
PGActiveNic1        :
StandbyNic1         :
PGName2             :
PGVLanId2           :
PGAllowPromiscuous2 :
PGMacChanges2       :
PGForgedTransmits2  :
PGActiveNic2        :
StandbyNic2         :  

$Report = Get-Datacenter | %{
 
  $DCName = $_.Name
  $_ | Get-Cluster | %{
 
    $ClusterName = $_
    # Select only the first returned host
    $_ | Get-VMHost | Select-Object -First 1 | %{
 
      $HostID = $_ | Get-View
      $_ | Get-VirtualSwitch | %{
 
        $NetworkConfig = $_ | Select-Object `
          @{n='Datacenter';e={ $DCName }}, `
          @{n='Cluster';e={ $ClusterName }}, `
          @{n='vSwitch';e={ $_.Name }}, `
          @{n='vmNIC';e={ $_.NIC }}, `
          @{n='Ports';e={ $_.NumPorts }}
 
        # Virtual Switch information from the Host
 
        $NetworkSystem = Get-View $HostID.ConfigManager.NetworkSystem
        $VSwitch = $NetworkSystem.NetworkConfig.VSwitch | ?{ $_.Name -eq $NetworkConfig.VSwitch }
 		$NetworkConfig | Add-Member -Type NoteProperty -Name "Host" -Value $Hostid.Name
        $NetworkConfig | Add-Member -Type NoteProperty -Name "AllowPromiscuous" -Value $VSwitch.Spec.Policy.Security.AllowPromiscuous
        $NetworkConfig | Add-Member -Type NoteProperty -Name "MacChanges" -Value $VSwitch.Spec.Policy.Security.MacChanges
        $NetworkConfig | Add-Member -Type NoteProperty -Name "ForgedTransmits" -Value $VSwitch.Spec.Policy.Security.ForgedTransmits
        $NetworkConfig | Add-Member -Type NoteProperty -Name "ActiveNic" -Value "$($VSwitch.Spec.Policy.NicTeaming.NicOrder.ActiveNic)"
        $NetworkConfig | Add-Member -Type NoteProperty -Name "StandbyNic" -Value "$($VSwitch.Spec.Policy.NicTeaming.NicOrder.StandbyNic)"
 
        # Port Group Information from each Virtual Switch       
 
        # A simple ID for the Port Group (used for column / member name)
        $i = 1
 
        $_ | Get-VirtualPortGroup | %{
          $PortGroup = $_
          $PortGroupConfig = $NetworkSystem.NetworkConfig.PortGroup | ?{ $_.Spec.Name -eq $PortGroup.Name }
 
          $NetworkConfig | Add-Member -Type NoteProperty -Name "PGName$i" -Value $PortGroup.Name
          $NetworkConfig | Add-Member -Type NoteProperty -Name "PGVLanId$i" -Value $PortGroup.VLanId
          $NetworkConfig | Add-Member -Type NoteProperty -Name "PGAllowPromiscuous$i" -Value $PortGroupConfig.Spec.Policy.Security.AllowPromiscuous
          $NetworkConfig | Add-Member -Type NoteProperty -Name "PGMacChanges$i" -Value $PortGroupConfig.Spec.Policy.Security.MacChanges
          $NetworkConfig | Add-Member -Type NoteProperty -Name "PGForgedTransmits$i" -Value $PortGroupConfig.Spec.Policy.Security.ForgedTransmits
		  $NetworkConfig | Add-Member -Type NoteProperty -Name "PGActiveNic$i" -Value "$($PortGroupConfig.Spec.Policy.NicTeaming.NicOrder.ActiveNic)"
		  $NetworkConfig | Add-Member -Type NoteProperty -Name "StandbyNic$i" -Value "$($PortGroupConfig.Spec.Policy.NicTeaming.NicOrder.StandbyNic)"
          $i++
        }
 
        $NetworkConfig
      }
    }
  }
}
 
# Fix the object array, ensure all objects within the 
# array contain the same members (required for Format-Table / Export-CSV)
 
$Members = $Report | Select-Object `
  @{n='MemberCount';e={ ($_ | Get-Member).Count }}, `
  @{n='Members';e={ $_.PsObject.Properties | %{ $_.Name } }}
$AllMembers = ($Members | Sort-Object MemberCount -Descending)[0].Members
 
ForEach ($Entry in $Report) {
  ForEach ($Member in $AllMembers)
  {
    If (!($Entry | Get-Member -Name $Member))
    { 
      $Entry | Add-Member -Type NoteProperty -Name $Member -Value ""
    }
  }
}
 
$Report

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:

Select allOpen in new window

 

by: Chris-DentPosted on 2009-10-05 at 03:12:19ID: 25493783


Ah bugger, I think I have the problem now. Lets try this one?

Chris

$Report = Get-Datacenter | %{
 
  $DCName = $_.Name
  $_ | Get-Cluster | %{
 
    $ClusterName = $_
    # Select only the first returned host
    $_ | Get-VMHost | Select-Object -First 1 | %{
 
      $HostID = $_ | Get-View
      $_ | Get-VirtualSwitch | %{
 
        $NetworkConfig = $_ | Select-Object `
          @{n='Datacenter';e={ $DCName }}, `
          @{n='Cluster';e={ $ClusterName }}, `
          @{n='vSwitch';e={ $_.Name }}, `
          @{n='vmNIC';e={ $_.NIC }}, `
          @{n='Ports';e={ $_.NumPorts }}
 
        # Virtual Switch information from the Host
 
        $NetworkSystem = Get-View $HostID.ConfigManager.NetworkSystem
        $VSwitch = $NetworkSystem.NetworkConfig.VSwitch | ?{ $_.Name -eq $NetworkConfig.VSwitch }
                $NetworkConfig | Add-Member -Type NoteProperty -Name "Host" -Value $Hostid.Name
        $NetworkConfig | Add-Member -Type NoteProperty -Name "AllowPromiscuous" -Value $VSwitch.Spec.Policy.Security.AllowPromiscuous
        $NetworkConfig | Add-Member -Type NoteProperty -Name "MacChanges" -Value $VSwitch.Spec.Policy.Security.MacChanges
        $NetworkConfig | Add-Member -Type NoteProperty -Name "ForgedTransmits" -Value $VSwitch.Spec.Policy.Security.ForgedTransmits
        $NetworkConfig | Add-Member -Type NoteProperty -Name "ActiveNic" -Value "$($VSwitch.Spec.Policy.NicTeaming.NicOrder.ActiveNic)"
        $NetworkConfig | Add-Member -Type NoteProperty -Name "StandbyNic" -Value "$($VSwitch.Spec.Policy.NicTeaming.NicOrder.StandbyNic)"
 
        # Port Group Information from each Virtual Switch       
 
        # A simple ID for the Port Group (used for column / member name)
        $i = 1
 
        $_ | Get-VirtualPortGroup | %{
          $PortGroup = $_
          $PortGroupConfig = $NetworkSystem.NetworkConfig.PortGroup | ?{ $_.Spec.Name -eq $PortGroup.Name }
 
          $NetworkConfig | Add-Member -Type NoteProperty -Name "PGName$i" -Value $PortGroup.Name
          $NetworkConfig | Add-Member -Type NoteProperty -Name "PGVLanId$i" -Value $PortGroup.VLanId
          $NetworkConfig | Add-Member -Type NoteProperty -Name "PGAllowPromiscuous$i" -Value $PortGroupConfig.Spec.Policy.Security.AllowPromiscuous
          $NetworkConfig | Add-Member -Type NoteProperty -Name "PGMacChanges$i" -Value $PortGroupConfig.Spec.Policy.Security.MacChanges
          $NetworkConfig | Add-Member -Type NoteProperty -Name "PGForgedTransmits$i" -Value $PortGroupConfig.Spec.Policy.Security.ForgedTransmits
 
          $NetworkConfig | Add-Member -Type NoteProperty -Name "PGActiveNic$i" `
            -Value "$($PortGroupConfig.Spec.Policy.NicTeaming.NicOrder.ActiveNic)"
          If ($NetworkConfig."ActiveNic$i" -eq "") { $NetworkConfig.ActiveNic = "Inherited" }
 
          $NetworkConfig | Add-Member -Type NoteProperty -Name "StandbyNic$i" `
            -Value "$($PortGroupConfig.Spec.Policy.NicTeaming.NicOrder.StandbyNic)"
          If ($NetworkConfig."StandbyNic$i" -eq "") { $NetworkConfig.StandbyNic = "Inherited" }
          $i++
        }
 
        $NetworkConfig
      }
    }
  }
}
 
# Fix the object array, ensure all objects within the 
# array contain the same members (required for Format-Table / Export-CSV)
 
$Members = $Report | Select-Object `
  @{n='MemberCount';e={ ($_ | Get-Member).Count }}, `
  @{n='Members';e={ $_.PsObject.Properties | %{ $_.Name } }}
$AllMembers = ($Members | Sort-Object MemberCount -Descending)[0].Members
 
ForEach ($Entry in $Report) {
  ForEach ($Member in $AllMembers)
  {
    If (!($Entry | Get-Member -Name $Member))
    { 
      $Entry | Add-Member -Type NoteProperty -Name $Member -Value ""
    }
  }
}
 
$Report

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:

Select allOpen in new window

 

by: ryder0707Posted on 2009-10-05 at 03:36:39ID: 25493906

It works fine at first but then i removed the NICs from port group Service Console & vmkernel to make them "null" hoping to get "inherited" but when i run the script again...

Datacenter          : LabDC
Cluster             : myCluster
vSwitch             : vSwitch0
vmNIC               : {vmnic3, vmnic2, vmnic1, vmnic0}
Ports               : 64
Host                : 192.168.88.51
AllowPromiscuous    : False
MacChanges          : True
ForgedTransmits     : True
ActiveNic           : vmnic0 vmnic1 vmnic2 vmnic3
StandbyNic          : Inherited
PGName1             : Service Console
PGVLanId1           : 0
PGAllowPromiscuous1 : False
PGMacChanges1       : False
PGForgedTransmits1  : False
PGActiveNic1        :
StandbyNic1         :
PGName2             : VMkernel
PGVLanId2           : 0
PGAllowPromiscuous2 : False
PGMacChanges2       : False
PGForgedTransmits2  : False
PGActiveNic2        :
StandbyNic2         :

Datacenter          : LabDC
Cluster             : myCluster
vSwitch             : vSwitch1
vmNIC               : {vmnic5, vmnic4}
Ports               : 64
Host                : 192.168.88.51
AllowPromiscuous    : False
MacChanges          : True
ForgedTransmits     : True
ActiveNic           : vmnic4 vmnic5
StandbyNic          : Inherited
PGName1             : Virtual Machine Network
PGVLanId1           : 0
PGAllowPromiscuous1 : False
PGMacChanges1       : False
PGForgedTransmits1  : False
PGActiveNic1        :
StandbyNic1         :
PGName2             :
PGVLanId2           :
PGAllowPromiscuous2 :
PGMacChanges2       :
PGForgedTransmits2  :
PGActiveNic2        :
StandbyNic2         :


I also noticed "inherited" went into StandbyNic in vSwitch0
ActiveNic           : vmnic0 vmnic1 vmnic2 vmnic3
StandbyNic          : Inherited

Suppose to be like the previous script
ActiveNic           : vmnic0 vmnic1 vmnic2 vmnic3
StandbyNic          :

 

by: Chris-DentPosted on 2009-10-05 at 04:48:03ID: 25494279


Hmm.. Try this? I wonder if it's storing a Null value for that member.

Chris

$Report = Get-Datacenter | %{
 
  $DCName = $_.Name
  $_ | Get-Cluster | %{
 
    $ClusterName = $_
    # Select only the first returned host
    $_ | Get-VMHost | Select-Object -First 1 | %{
 
      $HostID = $_ | Get-View
      $_ | Get-VirtualSwitch | %{
 
        $NetworkConfig = $_ | Select-Object `
          @{n='Datacenter';e={ $DCName }}, `
          @{n='Cluster';e={ $ClusterName }}, `
          @{n='vSwitch';e={ $_.Name }}, `
          @{n='vmNIC';e={ $_.NIC }}, `
          @{n='Ports';e={ $_.NumPorts }}
 
        # Virtual Switch information from the Host
 
        $NetworkSystem = Get-View $HostID.ConfigManager.NetworkSystem
        $VSwitch = $NetworkSystem.NetworkConfig.VSwitch | ?{ $_.Name -eq $NetworkConfig.VSwitch }
                $NetworkConfig | Add-Member -Type NoteProperty -Name "Host" -Value $Hostid.Name
        $NetworkConfig | Add-Member -Type NoteProperty -Name "AllowPromiscuous" -Value $VSwitch.Spec.Policy.Security.AllowPromiscuous
        $NetworkConfig | Add-Member -Type NoteProperty -Name "MacChanges" -Value $VSwitch.Spec.Policy.Security.MacChanges
        $NetworkConfig | Add-Member -Type NoteProperty -Name "ForgedTransmits" -Value $VSwitch.Spec.Policy.Security.ForgedTransmits
        $NetworkConfig | Add-Member -Type NoteProperty -Name "ActiveNic" -Value "$($VSwitch.Spec.Policy.NicTeaming.NicOrder.ActiveNic)"
        $NetworkConfig | Add-Member -Type NoteProperty -Name "StandbyNic" -Value "$($VSwitch.Spec.Policy.NicTeaming.NicOrder.StandbyNic)"
 
        # Port Group Information from each Virtual Switch       
 
        # A simple ID for the Port Group (used for column / member name)
        $i = 1
 
        $_ | Get-VirtualPortGroup | %{
          $PortGroup = $_
          $PortGroupConfig = $NetworkSystem.NetworkConfig.PortGroup | ?{ $_.Spec.Name -eq $PortGroup.Name }
 
          $NetworkConfig | Add-Member -Type NoteProperty -Name "PGName$i" -Value $PortGroup.Name
          $NetworkConfig | Add-Member -Type NoteProperty -Name "PGVLanId$i" -Value $PortGroup.VLanId
          $NetworkConfig | Add-Member -Type NoteProperty -Name "PGAllowPromiscuous$i" -Value $PortGroupConfig.Spec.Policy.Security.AllowPromiscuous
          $NetworkConfig | Add-Member -Type NoteProperty -Name "PGMacChanges$i" -Value $PortGroupConfig.Spec.Policy.Security.MacChanges
          $NetworkConfig | Add-Member -Type NoteProperty -Name "PGForgedTransmits$i" -Value $PortGroupConfig.Spec.Policy.Security.ForgedTransmits
 
          $NetworkConfig | Add-Member -Type NoteProperty -Name "PGActiveNic$i" `
            -Value "$($PortGroupConfig.Spec.Policy.NicTeaming.NicOrder.ActiveNic)"
          If ($NetworkConfig."ActiveNic$i" -eq $Null) { $NetworkConfig.ActiveNic = "Inherited" }
 
          $NetworkConfig | Add-Member -Type NoteProperty -Name "StandbyNic$i" `
            -Value "$($PortGroupConfig.Spec.Policy.NicTeaming.NicOrder.StandbyNic)"
          If ($NetworkConfig."StandbyNic$i" -eq $Null) { $NetworkConfig.StandbyNic = "Inherited" }
          $i++
        }
 
        $NetworkConfig
      }
    }
  }
}
 
# Fix the object array, ensure all objects within the 
# array contain the same members (required for Format-Table / Export-CSV)
 
$Members = $Report | Select-Object `
  @{n='MemberCount';e={ ($_ | Get-Member).Count }}, `
  @{n='Members';e={ $_.PsObject.Properties | %{ $_.Name } }}
$AllMembers = ($Members | Sort-Object MemberCount -Descending)[0].Members
 
ForEach ($Entry in $Report) {
  ForEach ($Member in $AllMembers)
  {
    If (!($Entry | Get-Member -Name $Member))
    { 
      $Entry | Add-Member -Type NoteProperty -Name $Member -Value ""
    }
  }
}
 
$Report
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:

Select allOpen in new window

 

by: Chris-DentPosted on 2009-10-05 at 04:49:13ID: 25494284


> I also noticed "inherited" went into StandbyNic in vSwitch0

Will it always be the first switch that has that problem? If so, I can bypass it. If it varies there's not much I can do about that.

Chris

 

by: ryder0707Posted on 2009-10-05 at 04:54:36ID: 25494316

Sorry mate, now is a bit different, ActiveNic of each vSwitch is getting "Inherited"

Datacenter          : LabDC
Cluster             : myCluster
vSwitch             : vSwitch0
vmNIC               : {vmnic3, vmnic2, vmnic1, vmnic0}
Ports               : 64
Host                : 192.168.88.51
AllowPromiscuous    : False
MacChanges          : True
ForgedTransmits     : True
ActiveNic           : Inherited      <--------------------------------------------------
StandbyNic          :
PGName1             : Service Console
PGVLanId1           : 0
PGAllowPromiscuous1 : False
PGMacChanges1       : False
PGForgedTransmits1  : False
PGActiveNic1        :
StandbyNic1         :
PGName2             : VMkernel
PGVLanId2           : 0
PGAllowPromiscuous2 : False
PGMacChanges2       : False
PGForgedTransmits2  : False
PGActiveNic2        :
StandbyNic2         :

Datacenter          : LabDC
Cluster             : myCluster
vSwitch             : vSwitch1
vmNIC               : {vmnic5, vmnic4}
Ports               : 64
Host                : 192.168.88.51
AllowPromiscuous    : False
MacChanges          : True
ForgedTransmits     : True
ActiveNic           : Inherited      <--------------------------------------------------
StandbyNic          :
PGName1             : Virtual Machine Network
PGVLanId1           : 0
PGAllowPromiscuous1 : False
PGMacChanges1       : False
PGForgedTransmits1  : False
PGActiveNic1        : vmnic4 vmnic5
StandbyNic1         :
PGName2             :
PGVLanId2           :
PGAllowPromiscuous2 :
PGMacChanges2       :
PGForgedTransmits2  :
PGActiveNic2        :
StandbyNic2         :

 

by: Chris-DentPosted on 2009-10-05 at 05:07:47ID: 25494387


heh okay, bugs, lots of bugs.

This one please?

It tests both versions at once with a few fixes in it.

Chris

$Report = Get-Datacenter | %{
 
  $DCName = $_.Name
  $_ | Get-Cluster | %{
 
    $ClusterName = $_
    # Select only the first returned host
    $_ | Get-VMHost | Select-Object -First 1 | %{
 
      $HostID = $_ | Get-View
      $_ | Get-VirtualSwitch | %{
 
        $NetworkConfig = $_ | Select-Object `
          @{n='Datacenter';e={ $DCName }}, `
          @{n='Cluster';e={ $ClusterName }}, `
          @{n='vSwitch';e={ $_.Name }}, `
          @{n='vmNIC';e={ $_.NIC }}, `
          @{n='Ports';e={ $_.NumPorts }}
 
        # Virtual Switch information from the Host
 
        $NetworkSystem = Get-View $HostID.ConfigManager.NetworkSystem
        $VSwitch = $NetworkSystem.NetworkConfig.VSwitch | ?{ $_.Name -eq $NetworkConfig.VSwitch }
        $NetworkConfig | Add-Member -Type NoteProperty -Name "Host" -Value $Hostid.Name
        $NetworkConfig | Add-Member -Type NoteProperty -Name "AllowPromiscuous" -Value $VSwitch.Spec.Policy.Security.AllowPromiscuous
        $NetworkConfig | Add-Member -Type NoteProperty -Name "MacChanges" -Value $VSwitch.Spec.Policy.Security.MacChanges
        $NetworkConfig | Add-Member -Type NoteProperty -Name "ForgedTransmits" -Value $VSwitch.Spec.Policy.Security.ForgedTransmits
        $NetworkConfig | Add-Member -Type NoteProperty -Name "ActiveNic" -Value "$($VSwitch.Spec.Policy.NicTeaming.NicOrder.ActiveNic)"
        $NetworkConfig | Add-Member -Type NoteProperty -Name "StandbyNic" -Value "$($VSwitch.Spec.Policy.NicTeaming.NicOrder.StandbyNic)"
 
        # Port Group Information from each Virtual Switch       
 
        # A simple ID for the Port Group (used for column / member name)
        $i = 1
 
        $_ | Get-VirtualPortGroup | %{
          $PortGroup = $_
          $PortGroupConfig = $NetworkSystem.NetworkConfig.PortGroup | ?{ $_.Spec.Name -eq $PortGroup.Name }
 
          $NetworkConfig | Add-Member -Type NoteProperty -Name "PGName$i" -Value $PortGroup.Name
          $NetworkConfig | Add-Member -Type NoteProperty -Name "PGVLanId$i" -Value $PortGroup.VLanId
          $NetworkConfig | Add-Member -Type NoteProperty -Name "PGAllowPromiscuous$i" -Value $PortGroupConfig.Spec.Policy.Security.AllowPromiscuous
          $NetworkConfig | Add-Member -Type NoteProperty -Name "PGMacChanges$i" -Value $PortGroupConfig.Spec.Policy.Security.MacChanges
          $NetworkConfig | Add-Member -Type NoteProperty -Name "PGForgedTransmits$i" -Value $PortGroupConfig.Spec.Policy.Security.ForgedTransmits
 
          #
          # Testing for blank value
          #
 
          $NetworkConfig | Add-Member -Type NoteProperty -Name "PGActiveNic$i-Blank" `
            -Value "$($PortGroupConfig.Spec.Policy.NicTeaming.NicOrder.ActiveNic)"
          If ($NetworkConfig."PGActiveNic$i-Blank".Trim() -eq "") { $NetworkConfig."PGActiveNic$i-Blank" = "Inherited" }
 
          $NetworkConfig | Add-Member -Type NoteProperty -Name "PGStandbyNic$i-Blank" `
            -Value "$($PortGroupConfig.Spec.Policy.NicTeaming.NicOrder.StandbyNic)"
          If ($NetworkConfig."PGStandbyNic$i-Blank".Trim() -eq "") { $NetworkConfig."PGStandbyNic$i-Blank" = "Inherited" }
 
          #
          # Testing for Null
          #
 
          If ($PortGroupConfig.Spec.Policy.NicTeaming.NicOrder.ActiveNic) {
            $NetworkConfig | Add-Member -Type NoteProperty -Name "PGActiveNic$i-Null" `
              -Value "$($PortGroupConfig.Spec.Policy.NicTeaming.NicOrder.ActiveNic)"
          } Else {
            $NetworkConfig | Add-Member -Type NoteProperty -Name "PGActiveNic$i-Null" -Value "Inherited"
          }
          
          If ($PortGroupConfig.Spec.Policy.NicTeaming.NicOrder.StandbyNic) {
            $NetworkConfig | Add-Member -Type NoteProperty -Name "PGStandbyNic$i-Null" `
            -Value "$($PortGroupConfig.Spec.Policy.NicTeaming.NicOrder.StandbyNic)"
          } Else {
            $NetworkConfig."PGStandbyNic$i-Null" = "Inherited"
          }
 
          $i++
        }
 
        $NetworkConfig
      }
    }
  }
}

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:

Select allOpen in new window

 

by: ryder0707Posted on 2009-10-05 at 17:24:47ID: 25501072

Got this error

Property 'PGStandbyNic1-Null' cannot be found on this object; make sure it exists and is settable.
At :line:75 char:27
+             $NetworkConfig. <<<< "PGStandbyNic$i-Null" = "Inherited"

 

by: Chris-DentPosted on 2009-10-06 at 02:08:24ID: 25503015


Oops. And again...

Chris

$Report = Get-Datacenter | %{
 
  $DCName = $_.Name
  $_ | Get-Cluster | %{
 
    $ClusterName = $_
    # Select only the first returned host
    $_ | Get-VMHost | Select-Object -First 1 | %{
 
      $HostID = $_ | Get-View
      $_ | Get-VirtualSwitch | %{
 
        $NetworkConfig = $_ | Select-Object `
          @{n='Datacenter';e={ $DCName }}, `
          @{n='Cluster';e={ $ClusterName }}, `
          @{n='vSwitch';e={ $_.Name }}, `
          @{n='vmNIC';e={ $_.NIC }}, `
          @{n='Ports';e={ $_.NumPorts }}
 
        # Virtual Switch information from the Host
 
        $NetworkSystem = Get-View $HostID.ConfigManager.NetworkSystem
        $VSwitch = $NetworkSystem.NetworkConfig.VSwitch | ?{ $_.Name -eq $NetworkConfig.VSwitch }
        $NetworkConfig | Add-Member -Type NoteProperty -Name "Host" -Value $Hostid.Name
        $NetworkConfig | Add-Member -Type NoteProperty -Name "AllowPromiscuous" -Value $VSwitch.Spec.Policy.Security.AllowPromiscuous
        $NetworkConfig | Add-Member -Type NoteProperty -Name "MacChanges" -Value $VSwitch.Spec.Policy.Security.MacChanges
        $NetworkConfig | Add-Member -Type NoteProperty -Name "ForgedTransmits" -Value $VSwitch.Spec.Policy.Security.ForgedTransmits
        $NetworkConfig | Add-Member -Type NoteProperty -Name "ActiveNic" -Value "$($VSwitch.Spec.Policy.NicTeaming.NicOrder.ActiveNic)"
        $NetworkConfig | Add-Member -Type NoteProperty -Name "StandbyNic" -Value "$($VSwitch.Spec.Policy.NicTeaming.NicOrder.StandbyNic)"
 
        # Port Group Information from each Virtual Switch       
 
        # A simple ID for the Port Group (used for column / member name)
        $i = 1
 
        $_ | Get-VirtualPortGroup | %{
          $PortGroup = $_
          $PortGroupConfig = $NetworkSystem.NetworkConfig.PortGroup | ?{ $_.Spec.Name -eq $PortGroup.Name }
 
          $NetworkConfig | Add-Member -Type NoteProperty -Name "PGName$i" -Value $PortGroup.Name
          $NetworkConfig | Add-Member -Type NoteProperty -Name "PGVLanId$i" -Value $PortGroup.VLanId
          $NetworkConfig | Add-Member -Type NoteProperty -Name "PGAllowPromiscuous$i" -Value $PortGroupConfig.Spec.Policy.Security.AllowPromiscuous
          $NetworkConfig | Add-Member -Type NoteProperty -Name "PGMacChanges$i" -Value $PortGroupConfig.Spec.Policy.Security.MacChanges
          $NetworkConfig | Add-Member -Type NoteProperty -Name "PGForgedTransmits$i" -Value $PortGroupConfig.Spec.Policy.Security.ForgedTransmits
 
          #
          # Testing for blank value
          #
 
          $NetworkConfig | Add-Member -Type NoteProperty -Name "PGActiveNic$i-Blank" `
            -Value "$($PortGroupConfig.Spec.Policy.NicTeaming.NicOrder.ActiveNic)"
          If ($NetworkConfig."PGActiveNic$i-Blank".Trim() -eq "") { $NetworkConfig."PGActiveNic$i-Blank" = "Inherited" }
 
          $NetworkConfig | Add-Member -Type NoteProperty -Name "PGStandbyNic$i-Blank" `
            -Value "$($PortGroupConfig.Spec.Policy.NicTeaming.NicOrder.StandbyNic)"
          If ($NetworkConfig."PGStandbyNic$i-Blank".Trim() -eq "") { $NetworkConfig."PGStandbyNic$i-Blank" = "Inherited" }
 
          #
          # Testing for Null
          #
 
          If ($PortGroupConfig.Spec.Policy.NicTeaming.NicOrder.ActiveNic) {
            $NetworkConfig | Add-Member -Type NoteProperty -Name "PGActiveNic$i-Null" `
              -Value "$($PortGroupConfig.Spec.Policy.NicTeaming.NicOrder.ActiveNic)"
          } Else {
            $NetworkConfig | Add-Member -Type NoteProperty -Name "PGActiveNic$i-Null" -Value "Inherited"
          }
          
          If ($PortGroupConfig.Spec.Policy.NicTeaming.NicOrder.StandbyNic) {
            $NetworkConfig | Add-Member -Type NoteProperty -Name "PGStandbyNic$i-Null" `
              -Value "$($PortGroupConfig.Spec.Policy.NicTeaming.NicOrder.StandbyNic)"
          } Else {
            $NetworkConfig | Add-Member -Type NoteProperty -Name "PGStandbyNic$i-Null" -Value "Inherited"
          }
 
          $i++
        }
 
        $NetworkConfig
      }
    }
  }
}
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:

Select allOpen in new window

 

by: ryder0707Posted on 2009-10-06 at 02:39:00ID: 25503185

Datacenter          : LabDC
Cluster             : myCluster
vSwitch             : vSwitch0
vmNIC               : {vmnic3, vmnic2, vmnic1, vmnic0}
Ports               : 64
Host                : 192.168.88.51
AllowPromiscuous    : False
MacChanges          : True
ForgedTransmits     : True
ActiveNic           : vmnic0 vmnic1 vmnic2 vmnic3
StandbyNic          :
PGName1             : Service Console
PGVLanId1           : 0
PGAllowPromiscuous1 : False
PGMacChanges1       : False
PGForgedTransmits1  : False
PGActiveNic1-Blank  : Inherited
PGStandbyNic1-Blank : Inherited
PGActiveNic1-Null   : Inherited
PGStandbyNic1-Null  : Inherited
PGName2             : VMkernel
PGVLanId2           : 0
PGAllowPromiscuous2 : False
PGMacChanges2       : False
PGForgedTransmits2  : False
PGActiveNic2-Blank  : Inherited
PGStandbyNic2-Blank : Inherited
PGActiveNic2-Null   : Inherited
PGStandbyNic2-Null  : Inherited


Datacenter          : LabDC
Cluster             : myCluster
vSwitch             : vSwitch1
vmNIC               : {vmnic5, vmnic4}
Ports               : 64
Host                : 192.168.88.51
AllowPromiscuous    : False
MacChanges          : True
ForgedTransmits     : True
ActiveNic           : vmnic4 vmnic5
StandbyNic          :
PGName1             : Virtual Machine Network
PGVLanId1           : 0
PGAllowPromiscuous1 : False
PGMacChanges1       : False
PGForgedTransmits1  : False
PGActiveNic1-Blank  : vmnic4 vmnic5
PGStandbyNic1-Blank : Inherited
PGActiveNic1-Null   : vmnic4 vmnic5
PGStandbyNic1-Null  : Inherited

 

by: Chris-DentPosted on 2009-10-06 at 02:40:06ID: 25503192


Is that right or wrong?

Chris

 

by: ryder0707Posted on 2009-10-06 at 02:51:26ID: 31635774

Wow! Sorry i just realized it actually works! I will open another question to further optimize this script i think this part is done now!
Superb!

 

by: Chris-DentPosted on 2009-10-06 at 03:01:39ID: 25503320


Ahh phew :)

Feel free to drop either the Null or Blank version, it only needs the one to work properly.

For example...

Chris

$Report = Get-Datacenter | %{
 
  $DCName = $_.Name
  $_ | Get-Cluster | %{
 
    $ClusterName = $_
    # Select only the first returned host
    $_ | Get-VMHost | Select-Object -First 1 | %{
 
      $HostID = $_ | Get-View
      $_ | Get-VirtualSwitch | %{
 
        $NetworkConfig = $_ | Select-Object `
          @{n='Datacenter';e={ $DCName }}, `
          @{n='Cluster';e={ $ClusterName }}, `
          @{n='vSwitch';e={ $_.Name }}, `
          @{n='vmNIC';e={ $_.NIC }}, `
          @{n='Ports';e={ $_.NumPorts }}
 
        # Virtual Switch information from the Host
 
        $NetworkSystem = Get-View $HostID.ConfigManager.NetworkSystem
        $VSwitch = $NetworkSystem.NetworkConfig.VSwitch | ?{ $_.Name -eq $NetworkConfig.VSwitch }
        $NetworkConfig | Add-Member -Type NoteProperty -Name "Host" -Value $Hostid.Name
        $NetworkConfig | Add-Member -Type NoteProperty -Name "AllowPromiscuous" -Value $VSwitch.Spec.Policy.Security.AllowPromiscuous
        $NetworkConfig | Add-Member -Type NoteProperty -Name "MacChanges" -Value $VSwitch.Spec.Policy.Security.MacChanges
        $NetworkConfig | Add-Member -Type NoteProperty -Name "ForgedTransmits" -Value $VSwitch.Spec.Policy.Security.ForgedTransmits
        $NetworkConfig | Add-Member -Type NoteProperty -Name "ActiveNic" -Value "$($VSwitch.Spec.Policy.NicTeaming.NicOrder.ActiveNic)"
        $NetworkConfig | Add-Member -Type NoteProperty -Name "StandbyNic" -Value "$($VSwitch.Spec.Policy.NicTeaming.NicOrder.StandbyNic)"
 
        # Port Group Information from each Virtual Switch       
 
        # A simple ID for the Port Group (used for column / member name)
        $i = 1
 
        $_ | Get-VirtualPortGroup | %{
          $PortGroup = $_
          $PortGroupConfig = $NetworkSystem.NetworkConfig.PortGroup | ?{ $_.Spec.Name -eq $PortGroup.Name }
 
          $NetworkConfig | Add-Member -Type NoteProperty -Name "PGName$i" -Value $PortGroup.Name
          $NetworkConfig | Add-Member -Type NoteProperty -Name "PGVLanId$i" -Value $PortGroup.VLanId
          $NetworkConfig | Add-Member -Type NoteProperty -Name "PGAllowPromiscuous$i" -Value $PortGroupConfig.Spec.Policy.Security.AllowPromiscuous
          $NetworkConfig | Add-Member -Type NoteProperty -Name "PGMacChanges$i" -Value $PortGroupConfig.Spec.Policy.Security.MacChanges
          $NetworkConfig | Add-Member -Type NoteProperty -Name "PGForgedTransmits$i" -Value $PortGroupConfig.Spec.Policy.Security.ForgedTransmits
 
          #
          # Testing for blank value
          #
 
          $NetworkConfig | Add-Member -Type NoteProperty -Name "PGActiveNic$i" `
            -Value "$($PortGroupConfig.Spec.Policy.NicTeaming.NicOrder.ActiveNic)"
          If ($NetworkConfig."PGActiveNic$i".Trim() -eq "") { $NetworkConfig."PGActiveNic$i" = "Inherited" }
 
          $NetworkConfig | Add-Member -Type NoteProperty -Name "PGStandbyNic$i" `
            -Value "$($PortGroupConfig.Spec.Policy.NicTeaming.NicOrder.StandbyNic)"
          If ($NetworkConfig."PGStandbyNic$i".Trim() -eq "") { $NetworkConfig."PGStandbyNic$i" = "Inherited" }
 
          $i++
        }
 
        $NetworkConfig
      }
    }
  }
}

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:

Select allOpen in new window

 

by: ryder0707Posted on 2009-10-06 at 03:11:36ID: 25503360

Yes noted! Thanks!
More points for you, see my next question http://www.experts-exchange.com/Programming/Languages/Scripting/Q_24788247.html

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...