Note
Access to this page requires authorization. You can try signing in or .
Access to this page requires authorization. You can try .
Add-AzVMNetworkInterface
- Module:
- Az.Compute Module
Adds a network interface to a virtual machine.
Syntax
GetNicFromNicId (Default)
Add-AzVMNetworkInterface
[-VM] <PSVirtualMachine>
[-Id] <String>
[-Primary]
[-DeleteOption <String>]
[-DefaultProfile <IAzureContextContainer>]
[<CommonParameters>]
GetNicFromNicObject
Add-AzVMNetworkInterface
[-VM] <PSVirtualMachine>
[-NetworkInterface] <System.Collections.Generic.List`1[Microsoft.Azure.Management.Internal.Network.Common.INetworkInterfaceReference]>
[-DeleteOption <String>]
[-DefaultProfile <IAzureContextContainer>]
[<CommonParameters>]
Description
The Add-AzVMNetworkInterface 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.
Examples
Example 1: Add a network interface to a new virtual machine
$VirtualMachine = New-AzVMConfig -VMName "VirtualMachine07" -VMSize "Standard_A1"
Add-AzVMNetworkInterface -VM $VirtualMachine -Id "/subscriptions/46fc8ea4-2de6-4179-8ab1-365da4121af4/resourceGroups/contoso/providers/Microsoft.Network/networkInterfaces/sshNIC"
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.
Example 2: Add a network interface to an existing virtual machine
$VirtualMachine = Get-AzVM -ResourceGroupName "ResourceGroup11" -Name "VirtualMachine07"
Add-AzVMNetworkInterface -VM $VirtualMachine -Id "/subscriptions/46fc8ea4-2de6-4179-8ab1-365da4121af4/resourceGroups/contoso/providers/Microsoft.Network/networkInterfaces/sshNIC"
Update-AzVM -ResourceGroupName "ResourceGroup11" -VM $VirtualMachine
The first command gets the virtual machine named VirtualMachine07 by using the Get-AzVM cmdlet. 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.
Parameters
-DefaultProfile
The credentials, account, tenant, and subscription used for communication with azure.
Parameter properties
| Type: | IAzureContextContainer |
| Default value: | None |
| Supports wildcards: | False |
| DontShow: | False |
| Aliases: | AzContext, AzureRmContext, AzureCredential |
Parameter sets
-DeleteOption
Specifies Network Interface delete option after VM deletion. Options are Detach, Delete
Parameter properties
| Type: | String |
| Default value: | None |
| Supports wildcards: | False |
| DontShow: | False |
Parameter sets
-Id
Specifies the ID of a network interface to add to a virtual machine. You can use the Get-AzNetworkInterface cmdlet to obtain a network interface.
Parameter properties
| Type: | String |
| Default value: | None |
| Supports wildcards: | False |
| DontShow: | False |
| Aliases: | NicId, NetworkInterfaceId |
Parameter sets
-NetworkInterface
Specifies the network interface.
Parameter properties
| Type: | |
| Default value: | None |
| Supports wildcards: | False |
| DontShow: | False |
Parameter sets
-Primary
Indicates that this cmdlet adds the network interface as the primary interface.
Parameter properties
| Type: | SwitchParameter |
| Default value: | None |
| Supports wildcards: | False |
| DontShow: | False |
Parameter sets
-VM
Specifies a local virtual machine object to which to add a network interface. To create a virtual machine, use the New-AzVMConfig cmdlet. To obtain an existing virtual machine, use the Get-AzVM cmdlet.
Parameter properties
| Type: | PSVirtualMachine |
| Default value: | None |
| Supports wildcards: | False |
| DontShow: | False |
| Aliases: | VMProfile |
Parameter sets
CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.
Inputs
PSVirtualMachine
String
List<T>
SwitchParameter
Outputs
PSVirtualMachine
Related Links
Azure PowerShell
Feedback
Was this page helpful?
