VMware Communities > Blogs > John Tuffin's Blog > 2008 > April > 02

Blog Posts

John Tuffin's Blog

Previous Next
0

This little snippet of PoweShell Code will create a virtual switch on an ESX Host. I found this while hunting through the VMware comunities for why I couldn't create a portgroup with Powershell. Using this code I was able to create a Virtual Switch called vSwitch1 with a VM portgroup called Production. I still have no idea what the policy setting does or do I know of any other values that could go there.

$ESXhost = "sc-gallium04.pso.vmware.com"

$vSwitch = "vSwitch1"

$user = "scriptuser"

$password = "vmware"

$VC = "10.18.138.187"

*
Get-VIServer $VC -User $user -Password $password

*

$NewSwitch = New-VirtualSwitch -vmhost (*Get-VMHost* $ESXhost ) -Name $vSwitch -NIC "vmnic1"

$net = Get-View(Get-View(*Get-VMHost* -Name $ESXHost).ID).configmanager.networksystem

$PortgroupSpec = New-Object vmware.Vim.hostportgroupspec

$PortgroupSpec.vswitchname = $vSwitch

$PortgroupSpec.Name = "Production"

$PortgroupSpec.policy = New-Object vmware.Vim.HostNetworkPolicy

$net.AddPortgroup($PortGroupSpec)



There are no comments on this post