Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Create variables to store the location and resource group names.
- $location = "<location azure stack>"
- $ResourceGroupName = "RG-IMG-LNX"
- New-AzureRmResourceGroup `
- -Name $ResourceGroupName `
- -Location $location
- # Create variables to store the storage account name and the storage account SKU information
- $StorageAccountName = "imgvmlnxstg"
- $SkuName = "Standard_LRS"
- # Create a new storage account
- $StorageAccount = New-AzureRMStorageAccount `
- -Location $location `
- -ResourceGroupName $ResourceGroupName `
- -Type $SkuName `
- -Name $StorageAccountName
- Set-AzureRmCurrentStorageAccount `
- -StorageAccountName $storageAccountName `
- -ResourceGroupName $resourceGroupName
- # Create a storage container to store the virtual machine image
- $containerName = 'osdisks'
- $container = New-AzureStorageContainer `
- -Name $containerName `
- -Permission Blob
- # Create a subnet configuration
- $subnetConfig = New-AzureRmVirtualNetworkSubnetConfig `
- -Name InternalSubnet `
- -AddressPrefix 192.168.1.0/24
- # Create a virtual network
- $vnet = New-AzureRmVirtualNetwork `
- -ResourceGroupName $ResourceGroupName `
- -Location $location `
- -Name IMG-LNX-Vnet `
- -AddressPrefix 192.168.0.0/16 `
- -Subnet $subnetConfig
- # Create a public IP address and specify a DNS name
- $pip = New-AzureRmPublicIpAddress `
- -ResourceGroupName $ResourceGroupName `
- -Location $location `
- -AllocationMethod Static `
- -IdleTimeoutInMinutes 4 `
- -Name "ippublic$(Get-Random)"
- # Create an inbound network security group rule for port 22
- $nsgRuleSSH = New-AzureRmNetworkSecurityRuleConfig -Name IMG-LNX-RuleRDP -Protocol Tcp `
- -Direction Inbound -Priority 1000 -SourceAddressPrefix * -SourcePortRange * -DestinationAddressPrefix * `
- -DestinationPortRange 22 -Access Allow
- # Create an inbound network security group rule for port 80
- $nsgRuleWeb = New-AzureRmNetworkSecurityRuleConfig -Name IMG-LNX-RuleWWW -Protocol Tcp `
- -Direction Inbound -Priority 1001 -SourceAddressPrefix * -SourcePortRange * -DestinationAddressPrefix * `
- -DestinationPortRange 80 -Access Allow
- # Create a network security group
- $nsg = New-AzureRmNetworkSecurityGroup -ResourceGroupName $ResourceGroupName -Location $location `
- -Name IMG-LNX-NSG -SecurityRules $nsgRuleSSH,$nsgRuleWeb
- # Create a virtual network card and associate it with public IP address and NSG
- $nic = New-AzureRmNetworkInterface `
- -Name IMG-WS-NIC `
- -ResourceGroupName $ResourceGroupName `
- -Location $location `
- -SubnetId $vnet.Subnets[0].Id `
- -PublicIpAddressId $pip.Id `
- -NetworkSecurityGroupId $nsg.Id
- # Define a credential object.
- $UserName='demouser'
- $securePassword = 'Password@123'| ConvertTo-SecureString -Force -AsPlainText
- $cred = New-Object System.Management.Automation.PSCredential ($UserName, $securePassword)
- # Create the virtual machine configuration object
- $VmName = "Ubuntu16"
- $VmSize = "Standard_D2_v2"
- $VirtualMachine = New-AzureRmVMConfig `
- -VMName $VmName `
- -VMSize $VmSize
- $VirtualMachine = Set-AzureRmVMOperatingSystem `
- -VM $VirtualMachine `
- -Linux `
- -ComputerName "Ubuntu16" `
- -Credential $cred
- $urlOfImageVhd = "<url vhd file in container blob>"
- #Create the OS disk URI
- $osDiskName = "OsDisk"
- $osDiskUri = '{0}vhds/{1}-{2}.vhd' -f `
- $StorageAccount.PrimaryEndpoints.Blob.ToString(),`
- $vmName.ToLower(), `
- $osDiskName
- # Sets the operating system disk properties on a virtual machine.
- $VirtualMachine = Set-AzureRmVMOSDisk `
- -VM $VirtualMachine `
- -Name $osDiskName `
- -VhdUri $OsDiskUri `
- -CreateOption FromImage -SourceImageUri $urlOfImageVhd -Linux | Add-AzureRmVMNetworkInterface -Id $nic.Id
- # Configure SSH Keys
- #$sshPublicKey = Get-Content "$env:USERPROFILE\.ssh\id_rsa.pub"
- # Adds the SSH Key to the virtual machine
- #Add-AzureRmVMSshPublicKey -VM $VirtualMachine `
- # -KeyData $sshPublicKey `
- # -Path "/home/azureuser/.ssh/authorized_keys"
- #Create the virtual machine.
- New-AzureRmVM `
- -ResourceGroupName $ResourceGroupName `
- -Location $location `
- -VM $VirtualMachine
Add Comment
Please, Sign In to add comment