Az-204 - Prep - How To - Creating VM Using Azure Powershell

 

Hello Everyone, 

Please find below commands to create VM using azure powershell

 

# Login
Connect-AzAccount -SubscriptionName "Demo Account"

# Set your subscription
Set-AzContext -SubscriptionName "Demo Account"

# Create a resource Group
New-AzResourceGroup -Name "psdemo-rg" -Location "CentralUS"

# Create a credential to use in VM Creation
$username = 'cloud_user_p_25e585de'
$password = ConvertTo-SecureString 'c6Wh3BrR6ArHzO&Cx4cA' -AsPlainText -Force
$WindowsCred = New-Object System.Management.Automation.PSCredential ($username, $password)

# Create Windows VM
New-AzVM `
-ResourceGroupName 'psdemo-rg' `
-Name 'psdemo-win-az4' `
-Image 'Win2019Datacenter'`
-Credential $WindowsCred `
-OpenPorts 3389 `
-AzJob

Get-AzResourceGroup
# 1-83eb7c26-playground-sandbox

New-AzVM `
-ResourceGroupName "1-83eb7c26-playground-sandbox" `
-Name "psdemo-win-az1" `
-Image "Win2019Datacenter" `
-Credential $WindowsCred `
-OpenPorts 3389

New-AzVm `
-ResourceGroupName "1-83eb7c26-playground-sandbox" `
-Name "aznewvm23" `
-Location 'eastus' `
-VirtualNetworkName "mynewazvm23" `
-SubnetName "default" `
-SecurityGroupName "mynewvmNSG23" `
-PublicIpAddressName "mypublicip23" `
-OpenPorts 80,3389 `
-AsJob

Get-Job 1

$j = Get-Job -Name "Long Running*"
$j

"""
PS my_learning/az204_prep> $j = Get-Job -Name 'Long Running*'

PS my_learning/az204_prep> $j


Id Name PSJobTypeName State HasMoreData Location Command
-- ---- ------------- ----- ----------- -------- -------
1 Long Running O… AzureLongRunni… Failed True localhost New-AzVM
2 Long Running O… AzureLongRunni… Failed True localhost New-AzVM
3 Long Running O… AzureLongRunni… Completed True localhost New-AzVM
"""

Get-AzVM -ResourceGroupName 1-83eb7c26-playground-sandbox

# Get the Public IP Address
Get-AzPublicIpAddress `
-ResourceGroupName "1-83eb7c26-playground-sandbox"`
-Name "psdemo-win-az" | Select-Object IpAddress

# Remove resource group after demo
Remove-AzResourceGroup -Name '1-83eb7c26-playground-sandbox'

0 comments:

Post a Comment