Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
PowerShell script to help manage an Azure VNet NSG rule.
[CmdletBinding()]
Param(
[Parameter(Mandatory=$True)]
[string]$resourceGroupName,
[Parameter(Mandatory=$True)]
[string]$networkSecurityGroupName,
[Parameter(Mandatory=$True)]
[string]$securityRuleName,
[Parameter(Mandatory=$True)]
[string]$allowOrDeny,
[Parameter(Mandatory=$True)]
[int]$priority
)
$nsg = Get-AzureRmNetworkSecurityGroup -ResourceGroupName $resourceGroupName -Name $networkSecurityGroupName
Set-AzureRmNetworkSecurityRuleConfig -Name $securityRuleName `
-NetworkSecurityGroup $nsg `
-Access $allowOrDeny `
-Protocol Tcp `
-SourcePortRange * `
-DestinationPortRange 5986 `
-SourceAddressPrefix * `
-Priority $priority `
-Direction Inbound `
-DestinationAddressPrefix *
Set-AzureRmNetworkSecurityGroup -NetworkSecurityGroup $nsg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment