Connect-VMNetwork Adapter

Connects a virtual network adapter to a virtual switch.

Syntax

Connect-VMNetworkAdapter
       [[-Name] <String[]>]
       [-SwitchName] <String>
       [-Passthru]
       [-CimSession <CimSession[]>]
       [-ComputerName <String[]>]
       [-Credential <PSCredential[]>]
       [-VMName] <String[]>
       [-WhatIf]
       [-Confirm]
       [<CommonParameters>]
Connect-VMNetworkAdapter
       [-VMNetworkAdapter] <VMNetworkAdapter[]>
       [-SwitchName] <String>
       [-Passthru]
       [-WhatIf]
       [-Confirm]
       [<CommonParameters>]
Connect-VMNetworkAdapter
       [-VMNetworkAdapter] <VMNetworkAdapter[]>
       [-VMSwitch] <VMSwitch>
       [-Passthru]
       [-WhatIf]
       [-Confirm]
       [<CommonParameters>]
Connect-VMNetworkAdapter
       [-VMNetworkAdapter] <VMNetworkAdapter[]>
       [-UseAutomaticConnection]
       [-Passthru]
       [-WhatIf]
       [-Confirm]
       [<CommonParameters>]
Connect-VMNetworkAdapter
       [[-Name] <String[]>]
       [-VMSwitch] <VMSwitch>
       [-Passthru]
       [-VMName] <String[]>
       [-WhatIf]
       [-Confirm]
       [<CommonParameters>]
Connect-VMNetworkAdapter
       [[-Name] <String[]>]
       [-UseAutomaticConnection]
       [-Passthru]
       [-CimSession <CimSession[]>]
       [-ComputerName <String[]>]
       [-Credential <PSCredential[]>]
       [-VMName] <String[]>
       [-WhatIf]
       [-Confirm]
       [<CommonParameters>]

Description

The Connect-VMNetworkAdapter cmdlet connects a virtual network adapter to a virtual switch.

Examples

Example 1

PS C:\> Connect-VMNetworkAdapter -VMName Test1,Test2 -Name Internet -SwitchName InternetAccess

Connects a virtual network adapter named Internet in virtual machines Test1 and Test2 to a virtual switch InternetAccess.

Example 2

PS C:\> Get-VMNetworkAdapter -VMName Test1 | Connect-VMNetworkAdapter -SwitchName InternetAccess

Connects a virtual network adapter in virtual machine Test1 to virtual switch InternetAccess.

Example 3

PS C:\> Get-VMSwitch InternetAccess | Connect-VMNetworkAdapter -VMName Test1

Connects a virtual network adapter in virtual machine Test1 to switch InternetAccess.

Required Parameters

-SwitchName

Specifies the name of the virtual switch to which the virtual network adapter is to be connected.

Type: String
Position: 1
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-UseAutomaticConnection

Specifies that the network adapter is to be connected to any virtual switch in the resource pool, rather than to a specific virtual switch.

Type: SwitchParameter
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-VMName

Specifies the name of the virtual machine in which the network adapter is to be connected.

Type: String[]
Position: 0
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-VMNetworkAdapter

Specifies the virtual network adapter to be connected.

Type: VMNetworkAdapter[]
Position: 0
Default value: None
Accept pipeline input: True (ByValue)
Accept wildcard characters: False
-VMSwitch

Specifies the virtual switch to which the virtual network adapter is to be connected.

Type: VMSwitch
Position: 2
Default value: None
Accept pipeline input: True (ByValue)
Accept wildcard characters: False

Optional Parameters

-CimSession

Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession or Get-CimSession cmdlet. The default is the current session on the local computer.

Type: CimSession[]
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-ComputerName

Specifies one or more virtual machine hosts on which the virtual network adapter is to be connected. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly.

Type: String[]
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-Confirm

Prompts you for confirmation before running the cmdlet.

Type: SwitchParameter
Aliases: cf
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False
-Credential

Specifies one or more user accounts that have permission to perform this action. The default is the current user.

Type: PSCredential[]
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-Name

Specifies the name of the virtual network adapter to be connected.

Type: String[]
Aliases: VMNetworkAdapterName
Position: 1
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-Passthru

Specifies that a Microsoft.HyperV.PowerShell.VMNetworkAdapter object is to be passed through to the pipeline representing the virtual network adapter to be connected.

Type: SwitchParameter
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-WhatIf

Shows what would happen if the cmdlet runs. The cmdlet is not run.

Type: SwitchParameter
Aliases: wi
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False

Outputs

None by default; Microsoft.HyperV.PowerShell.VMNetworkAdapter if PassThru is specified.