Azure PowerShell Tips
A bunch of tips on things I often have to do in PowerShell on Microsoft Azure
Tips
A simple login script
#Import-Module Azure
Param(
[Parameter(mandatory=$false)][string]$AzureSubscription = "YourSubscriptionID"
)
Write-host "Enter Azure login credentials..."
$Azurelogincred = Get-Credential
Write-host "Logging into Azure Account..."
Login-AzureRmAccount -Credential $Azurelogincred
Select-AzureRmSubscription -SubscriptionId $AzureSubscription
Creating a new Network Security Group (NSG) and copying rules from an existing group to it
$TemplateNSGRules = Get-AzureRmNetworkSecurityGroup -Name 'OldNSG' -ResourceGroupName 'OldNSGResourceName' | Get-AzureRmNetworkSecurityRuleConfig
New-AzureRmResourceGroup -Name 'NewNSGResourceName' -Location 'East US'
$NSG = New-AzureRmNetworkSecurityGroup -ResourceGroupName 'NewNSGResourceName' -Location 'East US' -Name 'NewNSGName'
foreach ($rule in $TemplateNSGRules) {
$NSG | Add-AzureRmNetworkSecurityRuleConfig -Name $rule.Name -Direction $rule.Direction -Priority $rule.Priority -Access $rule.Access -SourceAddressPrefix $rule.SourceAddressPrefix -SourcePortRange $rule.SourcePortRange -DestinationAddressPrefix $rule.DestinationAddressPrefix -DestinationPortRange $rule.DestinationPortRange -Protocol $rule.Protocol # -Description $rule.Description
$NSG | Set-AzureRmNetworkSecurityGroup
}