Set-HostNetworkAdapter
VMware: Configures the specified host network adapter
#Requires -Version 5.1
#Requires -Modules VMware.VimAutomation.Core
[CmdletBinding()]
Param(
[Parameter(Mandatory = $true)]
[string]$VIServer,
[Parameter(Mandatory = $true)]
[pscredential]$VICredential,
[Parameter(Mandatory = $true)]
[string]$HostName,
[Parameter(Mandatory = $true)]
[string]$AdapterName,
[bool]$AutomaticIPv6,
[switch]$Dhcp,
[bool]$FaultToleranceLoggingEnabled,
[string]$IPv4,
[string]$IPv6,
[bool]$IPv6Enabled,
[bool]$IPv6ThroughDhcp,
[string]$MACAddress,
[bool]$ManagementTrafficEnabled,
[int32]$MtuSize,
[string]$SubnetMask,
[bool]$VMotionEnabled,
[bool]$VsanTrafficEnabled
)
Process {
$vmServer = $null
try {
$vmServer = Connect-VIServer -Server $VIServer -Credential $VICredential -ErrorAction Stop
$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
$vAdapter = Get-VMHostNetworkAdapter -Server $vmServer -Name $AdapterName -VMHost $HostName -ErrorAction Stop
$cmdArgs = @{ ErrorAction = 'Stop'; VirtualNic = $vAdapter; Confirm = $false }
if ($PSBoundParameters.ContainsKey('AutomaticIPv6')) { $vAdapter = Set-VMHostNetworkAdapter @cmdArgs -AutomaticIPv6 $AutomaticIPv6 }
if ($PSBoundParameters.ContainsKey('Dhcp')) { $vAdapter = Set-VMHostNetworkAdapter @cmdArgs -Dhcp:$Dhcp }
if ($PSBoundParameters.ContainsKey('FaultToleranceLoggingEnabled')) { $vAdapter = Set-VMHostNetworkAdapter @cmdArgs -FaultToleranceLoggingEnabled $FaultToleranceLoggingEnabled }
if ($PSBoundParameters.ContainsKey('IPv4')) { $vAdapter = Set-VMHostNetworkAdapter @cmdArgs -IP $IPv4 }
if ($PSBoundParameters.ContainsKey('IPv6')) { $vAdapter = Set-VMHostNetworkAdapter @cmdArgs -IPv6 $IPv6 }
if ($PSBoundParameters.ContainsKey('IPv6Enabled')) { $vAdapter = Set-VMHostNetworkAdapter @cmdArgs -IPv6Enabled $IPv6Enabled }
if ($PSBoundParameters.ContainsKey('IPv6ThroughDhcp')) { $vAdapter = Set-VMHostNetworkAdapter @cmdArgs -IPv6ThroughDhcp $IPv6ThroughDhcp }
if ($PSBoundParameters.ContainsKey('MACAddress')) { $vAdapter = Set-VMHostNetworkAdapter @cmdArgs -Mac $MACAddress }
if ($PSBoundParameters.ContainsKey('ManagementTrafficEnabled')) { $vAdapter = Set-VMHostNetworkAdapter @cmdArgs -ManagementTrafficEnabled $ManagementTrafficEnabled }
if ($PSBoundParameters.ContainsKey('MtuSize')) { $vAdapter = Set-VMHostNetworkAdapter @cmdArgs -Mtu $MtuSize }
if ($PSBoundParameters.ContainsKey('SubnetMask')) { $vAdapter = Set-VMHostNetworkAdapter @cmdArgs -SubnetMask $SubnetMask }
if ($PSBoundParameters.ContainsKey('VMotionEnabled')) { $vAdapter = Set-VMHostNetworkAdapter @cmdArgs -VMotionEnabled $VMotionEnabled }
if ($PSBoundParameters.ContainsKey('VsanTrafficEnabled')) { $vAdapter = Set-VMHostNetworkAdapter @cmdArgs -VsanTrafficEnabled $VsanTrafficEnabled }
$result = $vAdapter | Select-Object *
foreach ($item in $result) {
$item | Add-Member -NotePropertyName 'Timestamp' -NotePropertyValue $timestamp -Force
Write-Output $item
}
}
catch { throw }
finally { if ($null -ne $vmServer) { Disconnect-VIServer -Server $vmServer -Force -Confirm:$false -ErrorAction SilentlyContinue } }
}IP address or DNS name of the vSphere server
PSCredential object for authenticating with the server
Name of the host whose network adapter to modify
Name of the host network adapter to modify
IPv6 address obtained through router advertisement
Off
Use DHCP for the host network adapter
Enable Fault Tolerance logging
IPv4 address in dot notation
IPv6 address
Enable IPv6 configuration
IPv6 address obtained through DHCP
MAC address of the virtual network adapter
Enable the network adapter for management traffic
MTU size
Subnet mask for the NIC
Enable for VMotion
Enable Virtual SAN traffic