Edit

Share via


Set-AzureNetworkSecurityGroupAssociation

Associates a network security group to a virtual machine, PaaS role, or network adapter.

Note

The cmdlets referenced in this documentation are for managing legacy Azure resources that use Azure Service Manager (ASM) APIs. This legacy PowerShell module isn't recommended when creating new resources since ASM is scheduled for retirement. For more information, see Azure Service Manager retirement.

The Az PowerShell module is the recommended PowerShell module for managing Azure Resource Manager (ARM) resources with PowerShell.

Syntax

AddNetworkSecurityGroupAssociationToSubnet

Set-AzureNetworkSecurityGroupAssociation
    -Name <String>
    -VirtualNetworkName <String>
    -SubnetName <String>
    [-Force]
    [-PassThru]
    [-Profile <AzureSMProfile>]
    [<CommonParameters>]

AddNetworkSecurityGroupAssociationToIaaSRole

Set-AzureNetworkSecurityGroupAssociation
    -Name <String>
    -VM <PersistentVMRoleContext>
    -ServiceName <String>
    [-Force]
    [-PassThru]
    [-NetworkInterfaceName <String>]
    [-Profile <AzureSMProfile>]
    [<CommonParameters>]

AddNetworkSecurityGroupAssociationToPaaSRole

Set-AzureNetworkSecurityGroupAssociation
    -Name <String>
    -RoleName <String>
    -ServiceName <String>
    [-Force]
    [-PassThru]
    [-Slot <String>]
    [-NetworkInterfaceName <String>]
    [-Profile <AzureSMProfile>]
    [<CommonParameters>]

Description

The Set-AzureNetworkSecurityGroupAssociation cmdlet associates a network security group to a virtual machine, platform as a service (PaaS) role, or network adapter.

Examples

Example 1: Assign a virtual machine to a network security group

PS C:\> Get-AzureVM -ServiceName "ContosoService" -Name "ContosoVM06" | Set-AzureNetworkSecurityGroupAssociation -Name "ContosoNetworkSecurityGroup"

This command gets a virtual machine named ContosoVM06 for the service named ContosoService, and passes that virtual machine object to the current cmdlet. The current cmdlet assigns the network security group named ContosoNetworkSecurityGroup to that virtual machine.

Parameters

-Force

Forces the command to run without asking for user confirmation.

Parameter properties

Type:SwitchParameter
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-Name

Specifies the name of the network security group that this cmdlet sets.

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:Named
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

-NetworkInterfaceName

Specifies the name of the network adapter to which this cmdlet applies the network security group.

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

AddNetworkSecurityGroupAssociationToIaaSRole
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False
AddNetworkSecurityGroupAssociationToPaaSRole
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

-PassThru

Returns an object representing the item with which you are working. By default, this cmdlet does not generate any output.

Parameter properties

Type:SwitchParameter
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-Profile

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

Parameter properties

Type:AzureSMProfile
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-RoleName

Specifies the name of a PaaS role to which this cmdlet applies the network security group.

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

AddNetworkSecurityGroupAssociationToPaaSRole
Position:Named
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

-ServiceName

Specifies the name of a cloud service. The PaaS role belongs to the service that this parameter specifies.

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

AddNetworkSecurityGroupAssociationToIaaSRole
Position:Named
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False
AddNetworkSecurityGroupAssociationToPaaSRole
Position:Named
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

-Slot

Specifies a PaaS slot. The PaaS role for which this cmdlet sets the network security group has the slot that this parameter specifies. Valid values are:

  • Production
  • Staging

The default value is Production.

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

AddNetworkSecurityGroupAssociationToPaaSRole
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-SubnetName

Specifies the name of a subnet to which this cmdlet associates the network security group.

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

AddNetworkSecurityGroupAssociationToSubnet
Position:Named
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-VirtualNetworkName

Specifies the name of a virtual network that contains the subnet to which this cmdlet associates the network security group.

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

AddNetworkSecurityGroupAssociationToSubnet
Position:Named
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-VM

Specifies the virtual machine to which this cmdlet applies the network security group.

Parameter properties

Type:PersistentVMRoleContext
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

AddNetworkSecurityGroupAssociationToIaaSRole
Position:Named
Mandatory:True
Value from pipeline:True
Value from pipeline by property name:True
Value from remaining arguments:False

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.

Outputs

Boolean