Here is my issue. I am putting together a script to configure our ESXi 4 U1 hosts. During the configuration we need to set the vSwitch security to reject for allowPromiscuous, forgedTransmits, and macChanges. Here is the section and the error.
$vh01=get-vmhost myhost.domain.com
$vh01vsw0=$vh01 |get-virtualswitch -name "vSwitch2"
$vh01moref=$vh01 |% {get-view $_.Id}
$vh01morefconfig=$vh01moref.configmanager
$vh01netsys=$vh01morefconfig.networksystem
$vh01netsysmoref=get-view $vh01netsys
$swspec= New-Object Vmware.Vim.HostVirtualSwitchSpec
$swspec.NumPorts=24
$swspec.policy= New-Object Vmware.Vim.HostNetworkPolicy
$swspec.policy.security=New-Object Vmware.Vim.HostNetworkSecurityPolicy
$swspec.policy.security.allowPromiscuous=$false
$swspec.policy.security.forgedTransmits=$false
$swspec.policy.security.macChanges=$false
$vh01netsysmoref.UpdateVirtualSwitch($vh01vsw0.name,$swspec)
And the error I get is :
Exception calling "UpdateVirtualSwitch" with "2" argument(s): "A specified parame
ter was not correct.
"
At C:\ Docs\PowershellScripts\StateConfigScripts\switchsec_test.ps1:17 char:3
7
+ $vh01netsysmoref.UpdateVirtualSwitch <<<< ($vh01vsw0.name,$swspec)
+ CategoryInfo : NotSpecified: (
[], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
If I run $vh01vsw0.name I get the correct vSwitch string reported back. I have a script section to set the same on the portgroups and it works just fine. Here is that script section.
$vh01=get-vmhost myhost.domain.com
$vh01moref=$vh01 |% {get-view $_.Id}
$vh01morefconfig=$vh01moref.configmanager
$vh01netsys=$vh01morefconfig.networksystem
$vh01netsysmoref=get-view $vh01netsys
$pgspec= New-Object Vmware.vim.HostPortGroupSpec
$pgspec.vswitchname="vSwitch0"
$pgspec.name="Management Network"
$pgspec.vlanid="0"
$pgspec.policy=New-Object Vmware.Vim.HostnetworkPolicy
$pgspec.policy.security=New-Object Vmware.Vim.HostNetworkSecurityPolicy
$pgspec.policy.security.allowPromiscuous=$false
$pgspec.policy.security.forgedTransmits=$false
$pgspec.policy.security.macChanges=$false
$vh01netsysmoref.UpdatePortgroup($pgspec.name,$pgspec)
Is this something that has to be done during the vSwitch creation and can’t be changed after? Any help is greatly apprecieated!! Thanks in advance!!