Powercli script to create a new vswitch and enable it for iscsi

By | 9th December 2014

The following script creates a new vswitch by name iscsi
Adds vmnic1 as the physical adapter
adds the portgroup iscsi

Interesting Note: to make the portgroup as vmkernel easy method to say -ConsoleNic:$false.


#Configs

$VC=”172.16.1.17″ #vcenter server
$user=”root”
$password=’vmware’

Connect-VIServer -Server $VC -User $user -Password $password

$esxall=Get-VMHost -Server $VC

foreach($esx in $esxall){

$vswitch = New-VirtualSwitch -Name iscsi -Nic vmnic1 -VMHost $esx
New-VMHostNetworkAdapter -VMHost $esx -PortGroup iscsi -ConsoleNic:$false -VirtualSwitch iscsi

}