#This script is designed to allow you to configure switches on multiple hosts by #importing information from a prepopulated .csv file. vMotion switch created based #on Mike Laverick's posting http://www.rtfm-ed.co.uk/?p=1514 #!!!!!!!Values passed for Type are Case sensitive since comparisons are being made.!!!!!!! $getinfo = Import-Csv "\\\\file.csv" #need to input locatin of .CSV file Connect-VIServer -Server vCenterServer #Need to input appropriate vCenter Server $getinfo | % { $Type = $_.Type #!!!! Case Sensitive !!!!!! $gethost = Get-VMHost -Name $_.HostName $SwitchName = $_.SwitchName $PortGroup = $_.PortGroupName $Nic = $_.NIC $VLAN = $_.VLAN $IP = $_.IP $Subnet = $_.Subnet $kernelGW = $_.KernelGW If ($Type -eq "Switch") { $gethost | New-VirtualSwitch -Name $SwitchName -Nic $Nic } #Gets Switch object based on the value for SwitchName (required for several cmd-lets that do not accept Strings) #'If' statement is used since a vMotion type does not already have a switch configured which will throw up an error. If ($Type -ne "vMotion") { $getswitch = Get-VirtualSwitch -VMHost $gethost -Name $SwitchName } #Add additional NIC to vSwitch to create a Team If ($Type -eq "Team"){ $getswitch | Set-VirtualSwitch -Nic $Nic } #Add Portgroup to existing switch with VLAN IF ($Type -eq "Portgroup") { $getswitch | New-VirtualPortGroup $PortGroup -VLanId $VLAN } #Creates vMotion switch and configures vmkernel gateway (located under DNS and Routing in configuration tab) IF ($Type -eq "vMotion") { $newvswitch = New-VirtualSwitch -VMHost $gethost -Name $SwitchName -Nic $Nic $vmotion = New-VirtualPortGroup -VirtualSwitch $newvswitch -Name $PortGroup New-VMHostNetworkAdapter -VMHost $gethost -PortGroup $PortGroup -VirtualSwitch $newvswitch -IP $IP -SubnetMask $subnet -VMotionEnabled: $true $vmhostnetwork = get-vmhostnetwork $gethost set-vmhostnetwork -network $vmhostnetwork -vmkernelgateway $kernelGW } }