Automation

 View Only
  • 1.  Monitor vSwitch

    Posted Apr 01, 2011 09:50 PM

    I am trying to get the name of the ESX host, and the vSwitches, but I can't seem to get the ESX Hostname

    Get-VMHost | Get-VirtualSwitch | Get-NicTeamingPolicy

    Desired Output:

    Name          VirtualSwitch   ActiveNic       StandbyNic      UnusedNic       FailbackEnabled NotifySwitches
    ---------          -------------   ---------       ----------      ---------       --------------- --------------
    HostName   vSwitch0        {xsigo_xnic1}   {xsigo_xnic0}                   True            True
                          vSwitch1        {xsigo_xnic3...                                 True            True



  • 2.  RE: Monitor vSwitch

    Posted Apr 01, 2011 10:04 PM

    Optimal Output would be

    PS D:\Scripts> Get-VMHost | Get-VirtualSwitch | Get-NicTeamingPolicy | FL

    Hosthame                    :Hostname
    VirtualSwitch               : vSwitch0
    ActiveNic                     : {xnic1}
    StandbyNic                  : {xnic0}

    VirtualSwitch                : vSwitch1
    ActiveNic                      : {xnic3, xnic2}
    StandbyNic                   :



  • 3.  RE: Monitor vSwitch

    Posted Apr 01, 2011 10:31 PM

    Try something like this

    foreach($esx in Get-VMHost){
        foreach($sw in (Get-VirtualSwitch -VMHost $esx -Standard)){
            Get-NicTeamingPolicy -VirtualSwitch $sw | `
            Select @{N="Hostname";E={$esx.Name}},             @{N="VirtualSwitch";E={$sw.Name}},             @{N="ActiveNic";E={[string]::Join(',',$_.ActiveNic)}},             @{N="StandbyNic";E={[string]::Join(',',$_.StandbyNic)}}     } }


  • 4.  RE: Monitor vSwitch

    Posted Apr 01, 2011 11:04 PM

    How do you get the output to a file?  The following does not work.

    | Out-File c:\out.txt



  • 5.  RE: Monitor vSwitch
    Best Answer

    Posted Apr 01, 2011 11:28 PM

    One way of doing this, is like this

    $report = foreach($esx in Get-VMHost){
        foreach($sw in (Get-VirtualSwitch -VMHost $esx -Standard)){
            Get-NicTeamingPolicy -VirtualSwitch $sw | `
           
    Select @{N="Hostname";E={$esx.Name}},             @{N="VirtualSwitch";E={$sw.Name}},             @{N="ActiveNic";E={[string]::Join(',',$_.ActiveNic)}},             @{N="StandbyNic";E={[string]::Join(',',$_.StandbyNic)}} | ft -AutoSize
        } }
    $report | Out-File "C:\report.txt"