Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Enable switch rename #239

Merged
merged 4 commits into from
Jan 15, 2024
Merged

fix: Enable switch rename #239

merged 4 commits into from
Jan 15, 2024

Conversation

taliesins
Copy link
Owner

@taliesins taliesins commented Jan 14, 2024

Allow switch to be renamed

MarkusRannare and others added 4 commits January 31, 2023 14:36
* Updating a switch would cause the error "Set-VMSwitch : Cannot convert 'System.Object[]' to the type 'System.String' required by parameter 'NetAdapterName'."
* Changing a switch name would not be applied
…teaming) and failing an update. Perhaps its a particular property.

Tested with:
New-VMSwitch -Name testeme -NetAdapterName "Ethernet 2", "Ethernet"
Rename-VMSwitch -Name testeme -NewName testme2
Set-VMSwitch -Name testme2 -AllowManagementOS:$false
@taliesins
Copy link
Owner Author

@MarkusRannare not sure why you included these checks. Perhaps you can tell me how to reproduce problem. I suspect its a particular combination that is preventing a change to an attribute.

	if len(netAdapterNames) > 1 {
		return fmt.Errorf("[ERROR][hyperv] Can't update a switch with multiple net adapaters names (%v)", netAdapterNames)
	}
if ($vmSwitch.NetAdapterNames.length -gt 0) {
	$NetAdapterNames = [string]$vmSwitch.NetAdapterNames[0]
}

I ran into this problem with some attributes and I added this (is there another attribute we need here):

if ($NetAdapterNames) {
	$SetVmSwitchArgs.AllowManagementOS=$vmSwitch.AllowManagementOS
	$SetVmSwitchArgs.NetAdapterName=$NetAdapterNames
	#Updates not supported on:
	#-EnableEmbeddedTeaming $vmSwitch.EmbeddedTeamingEnabled
	#-EnableIov $vmSwitch.IovEnabled
	#-EnablePacketDirect $vmSwitch.PacketDirectEnabled
	#-MinimumBandwidthMode $minimumBandwidthMode
} else {
	$SetVmSwitchArgs.SwitchType=$switchType
	#Updates not supported on:
	#-EnableEmbeddedTeaming $vmSwitch.EmbeddedTeamingEnabled
	#-EnableIov $vmSwitch.IovEnabled
	#-EnablePacketDirect $vmSwitch.PacketDirectEnabled
	#-MinimumBandwidthMode $minimumBandwidthMode

	#not used unless interface is specified
	#-AllowManagementOS $vmSwitch.AllowManagementOS
}

@taliesins taliesins merged commit 7107093 into master Jan 15, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants