I spent a bunch of time scripting virtual networks under Hyper-V over the weekend – so this week I am going to share some of my scripts. The first one is a simple one: it creates a private – or “virtual machine only” – virtual network.
As you can see, all you need to do is to call the CreateSwitch method on the MSVM_VirtualSwitchManagementService. CreateSwitch takes four parameters:
- SwitchName: This is the unique name that is used to identify the virtual network switch. This can be any unique value, but Hyper-V always uses a GUID for this value, so my scripts follow suit.
- FriendlyName: This is the virtual switch name that is displayed in the Hyper-V management user interface.
- NumLearnableAddresses: This is the number of MAC address that the virtual network switch will be able to track. The larger this number is, the more memory will be used by the switch. 1024 is a good default value for this.
- ScopeOfResidence: This is the scope to be used by our authorization management framework. If this is left blank the switch will be created in the root authorization management scope – which is a good default.