First of all, I know nothing about Powershell, so this is probably a n00b error. :smileyblush:
I'm trying to change the portgroup of a specific network adapter in the VM, but it fails, and it looks like there is a problem with my syntax, and more specific my definition of the network adapter.
Please enlighten me about what i'm doing wrong, have tried several different syntaxes now without any luck.
[vSphere PowerCLI] C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI> Set-NetworkAdapter -NetworkAdapter "Network adapter 2" -Ne
tworkName "NAT" -vm win7-01
Set-NetworkAdapter : Cannot bind parameter 'NetworkAdapter'. Cannot convert the "Network adapter 2" value of type "System.String" to type "
VMware.VimAutomation.ViCore.Types.V1.VirtualDevice.NetworkAdapter".
At line:1 char:35
+ Set-NetworkAdapter -NetworkAdapter <<<< "Network adapter 2" -NetworkName "NAT" -vm win7-01
+ CategoryInfo : InvalidArgument: (:) [Set-NetworkAdapter], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,VMware.VimAutomation.ViCore.Cmdlets.Commands.VirtualDevice.SetNetworkAdapter
I think you should do this as follows
Get-NetworkAdapter -VM win7-01 | where {$_.Name -eq "Network adapter 2"} | Set-NetworkAdapter -NetworkName "NAT" -Confirm:$false
First you "get" the network adapters for the VM, then you filter out the one you want with the Where-Object cmdlet and finally you assign the adapter to the portgroup.
The -Confirm parameter avoids that you have to reply to confirm the change.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I think you should do this as follows
Get-NetworkAdapter -VM win7-01 | where {$_.Name -eq "Network adapter 2"} | Set-NetworkAdapter -NetworkName "NAT" -Confirm:$false
First you "get" the network adapters for the VM, then you filter out the one you want with the Where-Object cmdlet and finally you assign the adapter to the portgroup.
The -Confirm parameter avoids that you have to reply to confirm the change.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
That works perfectly, thank you very much!
Guess i'll have to try to learn more about filtering info with powershell...
I am also getting a similar error when i try to change a value.
$portgroup =(Get-VirtualPortGroup -Name MX_LAB_153)
(Get-virtualportgroup -name $portgroup).extensiondata.config.defaultportconfig.uplinkteamingpolicy.policy.value
output:loadbalance_loadbased
i got the below error when i ran this command to cahnge the policy to source id
(Set-virtualportgroup -name $portgroup).extensiondata.config.defaultportconfig.uplinkteamingpolicy.policy.value="loadbalance_srcid"
Error:
Set-VirtualPortGroup : Cannot bind parameter 'VirtualPortGroup'. Cannot convert the "mx_lab-153" value of type "System.String" to type "VMware.VimAutomation.ViCore.Types.V1.Host.Networking.VirtualPortGroup".
At C:\test.ps1:2 char:22
+ (Set-virtualportgroup <<<< -name $portgroup).extensiondata.config.defaultportconfig.uplinkteamingpolicy.policy.value='loadbalance_srcid'
+ CategoryInfo : InvalidArgument: (:) [Set-VirtualPortGroup], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,VMware.VimAutomation.ViCore.Cmdlets.Commands.SetVirtualPortGroup
how do i set the teamingpolicy to loadbalance_srcid using powershell on one/all dvportgroups?
looks like set-nicteamingpolicy/get-nicteamingpolicy only works with standard switch. any help is much appreciated.
I'm afraid you can set nicteaming like that.
Try using the Set-NicTeamingPolicy cmdlet.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
looks like Set-nicteamingpolicy only works wiht standard switch.
i cannot get it to work with any dvportgroup.
I see the link you sent for set-nicteaminpolicy . that syntax looks much better. will try that and see if it works. thx again
PowerCLI C:\files\scripts> get-virtualswitch -vmhost (get-vmhost tjaxl0104esx*) -name vSwitch1 | Get-NicTeamingPolicy
VirtualSwitch ActiveNic StandbyNic UnusedNic FailbackEnabled NotifySwitches
------------- --------- ---------- --------- --------------- --------------
vSwitch1 {vmnic0} True True
PowerCLI C:\files\scripts> get-virtualswitch -vmhost (get-vmhost tjaxl0104esx*) -name CSXT_Nexus_Test_Sw1-2 | Get-NicTeamingPolicy
Get-NicTeamingPolicy : Parameter set cannot be resolved using the specified named parameters.
At line:1 char:104
+ get-virtualswitch -vmhost (get-vmhost tjaxl0104esx*) -name CSXT_Nexus_Test_Sw1-2 | Get-NicTeamingPolicy <<<<
+ CategoryInfo : InvalidArgument: (CSXT_Nexus_Test_Sw1-2:PSObject) [Get-NicTeamingPolicy], ParameterBindingException
+ FullyQualifiedErrorId : AmbiguousParameterSet,VMware.VimAutomation.ViCore.Cmdlets.Commands.Host.GetNicTeamingPolicy
same command doesnt work on dvswitch
I'm afraid dvS is not yet supported by that cmdlet.
You could try my Set-dVSwPgTeam function from my dvSwitch scripting – Part 4 – NIC teaming post.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
this worked like a charm. Thx LucD
param ($vswitch)
Get-VirtualSwitch -name $vswitch | Get-VirtualPortGroup | ? { $_.name -notlike "*DVUplinks*" } | % {
$PortGroup = $_
Get-VdsDistributedPortgroup -name $portgroup | Set-VdsDVPortTeamingPolicy -LoadBalance loadbalance_srcid
#http://labs.vmware.com/flings/vdspowercli
#Add-PSSnapin VMware.VimAutomation.VdsComponent
#works on only 32-bit powercli