Posts

Showing posts with the label network

PowerShell Function to Extract Subnet/CIDR for a Pair of IP Addresses

Well, this one is hyper-specific... but in case anyone else needs to do something similar, I figure that I should share!  As a tiny part of a much bigger project, one of my customers gave me a list of VLAN IDs and the IP Ranges that they want to use on each VLAN.  Unfortunately, that list did not include either Subnet Mask or CIDR values, so I had to work backwards from the given ranges to determine what would be an acceptable Subnet Mask.  This process involves some annoying binary math, so you know that I put together a script to do it for me! I wrote the extract-CIDR function to accept two IP Addresses, and then to output the smallest subnet/CIDR that could contain those two IP Addresses (so they don't technically need to be the start and end of the range, but it's safer to use those two).  For example, if I give the script 192.168.0.1 and 192.168.0.254, I want to get back 192.168.0.0/24.  If I'm playing around with subnets though, I want to be able to give i...

Script to Move a VM to a New Portgroup and Update its Network Identity

Hey everyone - I recently put together a script to make it easier to move a VM around between various networks.  It moves the VM onto the specified Port Group and then uses VMTools to run a PowerShell script in the guest (this is for Windows VMs only, sorry!) to update its IP/DNS/Gateway/etc.  Since my old Gist'ing technique isn't working any more, so it's below as simple text (and it's on my GitHub if you want to grab it that way). But first, let's break it down a little bit!  The bulk of this script is really straight-forward.  The most interesting bit is using the PowerCLI Invoke-VMScript cmdlet to do the work inside the target VM's OS (since this operation will break network connectivity).  Invoke-VMScript is, on the surface, similar to the core PowerShell cmdlet Invoke-Command... but they way that they operate is completely different under the covers!  The practical difference that made the most impact for me is that Invoke-Command allows access to th...

Pulling Average VM Network Usage En Masse

One of my customers is considering moving some of their infrastructure around and wanted to get an idea about how their WAN connection might be impacted by the move.  They didn't have vROPS and we didn't want to enable greater vCenter logging due to space constraints on the SQL server (that tells you that we're working with some older systems, doesn't it!).  So, I decided that our best course of action would be to write a script that could run on an interval, collecting and summarizing the real-time statistics that we actually needed.  Hence the creation of summarize-VMNetUsage.ps1 ! This is a pretty straightforward script.  If you run it without any parameters, it will find the highest 20 second Average Network Usage stats from all VMs in an environment, then return a summary of its findings: VM Count, sum, average, maximum, minimum, and a date-stamp.  Then, the script enters a holding pattern until 1 hour has passed and it starts the process again.  It ...

Port Mirroring by SPAN or RSPAN on an HP C7000 Blade

This is just a heads-up to hopefully save someone else a bit of time and pain... but the HP Virtual Connect doesn't support SPAN or RSPAN to mirror traffic from a physical device into the chassis to, for example, a Virtual Machine.  Basically, Port Mirroring, such as through SPAN or RSPAN, uses unicast to duplicate network traffic from a source port or ports onto a destination port.  This technique is useful for troubleshooting, in case you can't get a packet capture running on either end of a network flow, or for monitoring (as was our intended use case). IANANG (I Am Not a Networking Guy), but my understanding is that the problem is due to the nature of a SPAN port and how those packets look to the Virtual Connect.  When Port Mirroring is configured, all traffic is duplicated and sent out to the Virtual Connect.  These packets are not changed in this process, keeping their original source and destination MAC addresses; the SPAN port is forwarding these packets t...

Pinging all VMs on an ESXi Host (or other vCenter Container)

Here's a quickie.  As part of this big vCenter forklift, we want to verify that all VMs are communicating on the network after they've been migrated to the destination systems.  I shudder to imagine someone typing out "ping vma" and then "ping vmb" etc. for all of these machines... and so I created this command to do the work for us!  It grabs the list of all VMs from the host esx01, then does two tests.  First, it checks to see if the vm has a hostname (from VMware tools), then it attempts to ping that hostname.  If the VM doesn't have a hostname or if that VM doesn't respond to ping, the command spits out a quick message saying that the VM failed to ping. get-vmhost *esx01* | get-vm | foreach {if(!($_.guest.hostname) -or !(Test-Connection $_.guest.hostname -count 1 -quiet)){echo "$($_.name) failed to ping"}} Quick note - this command uses the test-connection cmdlet, which was introduced in PowerShell 4.0.  You can use $psversiontable....

VM NIC Hardware Failure Issue

A few customers have been hit by an intermittent issue where virtual machines seem to reject their network adapters.  In Windows, this shows up as the guest OS reporting a hardware failure on the NIC (which, given that the NIC is virtual, is bit of a hard sell).  So, while the VM has a network adapter attached to it and it is connected to the network, the VM doesn’t get any network access.  If you open up device manager, the “general tab” for the network adapter will show an error (error 10 if memory serves).  When you try to update the driver on the NIC, it will fail to install it.  I’ve only ever seen this with the vmxnet3 adapter, but I’ve heard that it can affect e1000 as well. Typically, the VM’s network connectivity can be restored by some combination of removing the vNIC from the VM and adding it back (well, it’s technically a new one as it will have a new MAC address), reinstalling the VMTools and/or removing nonpresent NICs from the guest OS.  T...