VMware Cloud Community
michelvaillanco
Enthusiast
Enthusiast

Create a script to check network configuration

Hi,

I have a problem I'd love for you to help solve it.I run about 30 virtual environments that are not connected to each other. My problem is Whenever there is a problem with one of the servers the technicians come and connect the network cables poorly and cause problems.

I need to write a script that will check all of my pre-defined configuration that I did an If the settings are not correct then it will corrected them.

I forget to mention that I use VSphere 5.1..

Regards,

Michel V

0 Kudos
12 Replies
LucD
Leadership
Leadership

Can you give some more details, what exactly of your network configuration do you want to check ?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
michelvaillanco
Enthusiast
Enthusiast

Good morning,

My network configuration is very simply, I have only configured management and monitor conactions.The monitor conaction is to monitor a couple of ports from my network switch.   No Vlan's.

I have 1 NIC card with 6 ports.

Michel

0 Kudos
LucD
Leadership
Leadership

Still not quite sure I understand the question, but is it something like this that you want ?

Foreach($esx in Get-VMHost){

    $esxcli = Get-EsxCli -VMHost $esx

    $esxcli.network.nic.list() | Select @{N='VMHost';E={$esx.Name}},Name,MacAddress,Link

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
michelvaillanco
Enthusiast
Enthusiast

Hi,

My question was: is there any way to create a script that will check and fix ( if Necessary) my network configuration in my VMware VSphere 5.1 Environment?


Regards,


Michel V

0 Kudos
LucD
Leadership
Leadership

Perhaps if you could give one or more examples of what exactly you want to discover with the script ?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
michelvaillanco
Enthusiast
Enthusiast

Hi,

I have attached a png file with network configuration. the difranse is that insted of the vmotion configuration i have configure monitor port.

the same configuration is in all of the ESXI server in the company.

Alot of the time that the tech gays replace one of the server they forget to connect the wriht network cable to the rihat port.

The result of this process is that later some users complain that the port monitoring does not work and then I have to drive for an houre or more to configure the network as it shuld be. I would like to write a script that will configure back my network configuration as it shoud be.

Regards,

Michel

0 Kudos
LucD
Leadership
Leadership

You could do something like this, it will check your defined switch configuration with what is actually there, and correct if required

You can combine this with the 1st script I gave, that one checks of all the vNICs are Up.

$tgtConfig = @"

"vSwitch","vNic"

"vSwitch0","vmnic2/vmnic0"

"vSwitch1","vmnic5/vmnic4"

"@

foreach($esx in Get-VMHost){

    $tgtConfig | ConvertFrom-Csv -Delimiter ',' | %{

        $sw = Get-VirtualSwitch -Name $_.vSwitch -VMHost $esx

        $vnics = $_.vNic.Split('/')

        $missing = $false

        if($vnics | where{$sw.Nic -notcontains $_}){

            $missing = $true

        }

        if($missing){

            Set-VirtualSwitch -VirtualSwitch $sw -Nic $_.vNic -Confirm:$false

        }

    }

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
michelvaillanco
Enthusiast
Enthusiast

Hi,

Thank you for all your help but i have a couple question about the script:

1.  where I'm soppiest to put the IP address of my ESXI server?

2. How does the scrip know what is the right network configuration?

Regards,

Michel V

0 Kudos
LucD
Leadership
Leadership

The script will look at all your ESXi hosts.

You define the correct configuration (vswitch - vnic) in the variable at the top of the script.

I just created an example based on your screenshot.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
michelvaillanco
Enthusiast
Enthusiast

Hi,

I'v tryed the script but the resolt is not what i need.I only get the list of physical nics with the list of the vm nics.

Michel

0 Kudos
LucD
Leadership
Leadership

Perhaps it would be easier if you tell me what you want to see in the report ?

Use a dummy layout of the desired output.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
LittleNickey
Enthusiast
Enthusiast

I don't either fully understand exactly what you want to do, but maybe take a look at Set-VMHostNetworkAdapter command?

-- Oskar
0 Kudos