Azure Powershell

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

Assignment : PowerShell Azure resource

Management
TASK 1: Create a new resource group named MyResourceGroup in the
Azure region of your choice using PowerShell

We use the variable to use the variable to store the value


$resourceGroupName = "MyResourceGroup"
$location = "EastUS"
Command used: New-AzResourceGroup -Name $resourceGroupName -
Location $location
TASK 2: Within the MyResourceGroup, create a new storage account named
mystorageaccount with the following configurations: SKU: Standard_LRS Kind:
StorageV2

Create variable to store the values


$storageAccount = “newstorage7878”
$sku_name = “Standard_LRS”
$kind = “StorageV2”

Command used: New-AzStorageAccount -ResourceGroupName


$resourceGroupName -Name $storageAccount -SkuName $sku_name -Kind
$kind -Location $location
Task 3: Create a new virtual machine named MyVM in the MyResourceGroup
with the following specifications:
Image: Windows Server 2019 Datacenter
VM Size: Standard_DS1_v2
Username: azureuser
Password: <any password>

Command used: New-AzVM `


-ResourceGroupName "MyResourceGroup" `
-Name "MyVM" `
-Image "MicrosoftWindowsServer:WindowsServer:2019-Datacenter:latest" `
-Size "Standard_DS1_v2" `
-Credential (Get-Credential -UserName "azureuser" -Message "Enter your
password")`
-Location "EastUS"

This command will prompt you to enter the password for the "azureuser"
account and then create a virtual machine with the specified image, size,
username, and password in the "MyResourceGroup" resource group.
TASK 4: Create a new NSG named MyNSG with the following rules:
Allow inbound traffic on port 3389 (RDP) from any source.
Allow inbound traffic on port 80 (HTTP) from any source.
Command used:
# Create a new NSG
$nsg = New-AzNetworkSecurityGroup -Name "MyNSG" -ResourceGroupName
"MyResourceGroup" -Location "EastUS"

# Allow inbound RDP traffic on port 3389


$nsg | Add-AzNetworkSecurityRuleConfig -Name "Allow-RDP" -Priority 100 -
Access Allow -Protocol Tcp -Direction Inbound -SourceAddressPrefix * -
SourcePortRange * -DestinationAddressPrefix * -DestinationPortRange 3389

# Allow inbound HTTP traffic on port 80


$nsg | Add-AzNetworkSecurityRuleConfig -Name "Allow-HTTP" -Priority 200 -
Access Allow -Protocol Tcp -Direction Inbound -SourceAddressPrefix * -
SourcePortRange * -DestinationAddressPrefix * -DestinationPortRange 80

# Apply the NSG rules


Set-AzNetworkSecurityGroup -Name "MyNSG" -ResourceGroupName
"MyResourceGroup"
TASK 5: Attach the MyNSG to the network interface of MyVM.
Command Used: # Replace the following placeholders with actual values

$resourceGroupName = "MyResourceGroup"
$vmName =”MyVM"
$networkInterfaceName = "MyVM"

# Get the VM and network interface objects


$vm = Get-AzVM -ResourceGroupName $resourceGroupName -Name $vmName
$networkInterface = Get-AzNetworkInterface -ResourceGroupName
$resourceGroupName -Name $networkInterfaceName

# Attach the network interface to the VM


$vm | Add-AzVMNetworkInterface -Id $networkInterface.Id
# Update the VM
Update-AzVM -ResourceGroupName $resourceGroupName -VM $vm

You might also like