Share via


Add-AzureVMNetworkInterface

Add-AzureVMNetworkInterface

Adds a network interface to a virtual machine.

Syntax

Parameter Set: Default
Add-AzureVMNetworkInterface [-VM] <PSVirtualMachine> [-Id] <String> [[-Primary]] [-Profile <AzureProfile> ] [ <CommonParameters>]

Detailed Description

The Add-AzureVMNetworkInterface cmdlet adds a network interface to a virtual machine. You can add an interface when you create a virtual machine or add one to an existing virtual machine.

Parameters

-Id<String>

Specifies the ID of a network interface to add to a virtual machine. To obtain a network interface, use the Get-AzureNetworkInterface cmdlet.

Aliases

NicId,NetworkInterfaceId

Required?

true

Position?

2

Default Value

none

Accept Pipeline Input?

true(ByPropertyName)

Accept Wildcard Characters?

false

-Primary

Indicates that this cmdlet adds the network interface as the primary interface.

Aliases

none

Required?

false

Position?

3

Default Value

none

Accept Pipeline Input?

true(ByPropertyName)

Accept Wildcard Characters?

false

-Profile<AzureProfile>

Specifies the Azure profile from which this cmdlet reads. If you do not specify a profile, this cmdlet reads from the local default profile.

Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-VM<PSVirtualMachine>

Specifies a local virtual machine object to which to add a network interface. To create a virtual machine, use the New-AzureVMConfig cmdlet. To obtain an existing virtual machine, use the Get-AzureVM cmdlet.

Aliases

VMProfile

Required?

true

Position?

1

Default Value

none

Accept Pipeline Input?

true(ByValue,ByPropertyName)

Accept Wildcard Characters?

false

<CommonParameters>

This cmdlet supports the common parameters: -Verbose, -Debug, -ErrorAction, -ErrorVariable, -OutBuffer, and -OutVariable. For more information, see    about_CommonParameters (https://go.microsoft.com/fwlink/p/?LinkID=113216).

Inputs

The input type is the type of the objects that you can pipe to the cmdlet.

Outputs

The output type is the type of the objects that the cmdlet emits.

Examples

Example 1: Add a network interface to a new virtual machine

The first command creates a virtual machine object, and then stores it in the $VirtualMachine variable. The command assigns a name and size to the virtual machine.

The second command adds a network interface to the virtual machine stored in $VirtualMachine.

$VirtualMachine = New-AzureVMConfig -VMName "VirtualMachine07" -VMSize "Standard_A1" 
PS C:\> Add-AzureVMNetworkInterface -VM $VirtualMachine -Id "/subscriptions/46fc8ea4-2de6-4179-8ab1-365da4121af4/resourceGroups/contoso/providers/Microsoft.Network/networkInterfaces/sshNIC"

Example 2: Add a network interface to an existing virtual machine

The first command gets the virtual machine named VirtualMachine07 by using the Get-AzureVM cmldet. The command stores the virtual machine in the $VirtualMachine variable.

The second command adds a network interface to the virtual machine stored in $VirtualMachine.

The final command updates the state of the virtual machine stored in $VirtualMachine in ResourceGroup11.

$VirtualMachine = Get-AzureVM -ResourceGroupName "ResourceGroup11" -Name "VirtualMachine07"
PS C:\> Add-AzureVMNetworkInterface -VM $VirtualMachine -Id "/subscriptions/46fc8ea4-2de6-4179-8ab1-365da4121af4/resourceGroups/contoso/providers/Microsoft.Network/networkInterfaces/sshNIC"
PS C:\> Update-AzureVM -ResourceGroupName "ResourceGroup11" -Name " VirtualMachine07" -VM $VirtualMachine

Get-AzureNetworkInterface

New-AzureVMConfig

Get-AzureVM

Get-AzureAvailabilitySet