Skip to content

Instantly share code, notes, and snippets.

@imartinezm
Created January 29, 2017 18:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imartinezm/ac2af3c581e82171e3fad35207504b2c to your computer and use it in GitHub Desktop.
Save imartinezm/ac2af3c581e82171e3fad35207504b2c to your computer and use it in GitHub Desktop.
CREACION VM UBUNTU VIA POWERSHELL AZURE IMPLEMENTANDO XRDP
#Creado por Ivan Martinez Moran
#blog ivanmartinezm.wordpress.com
#Definiendo Variables
$localizacion="Canada Central"
$producto ="Canonical"
$edicion="UbuntuServer"
#Mostrando las versiones de Linux Ubuntu en Azure
Get-AzureRmVMImageSku -Location $localizacion -PublisherName $producto -Offer $edicion
# Declaracion de Recursos
#Grupo de Recursos
$ResourceGroupName = "ResourceGroupPeru"
$Location = "Canada Central"
#Definiendo Almacenamiento
$StorageName = "resourcestorage01"
$StorageType = "Standard_GRS"
## Definiendo la Red
$InterfaceName = "ServerInterface01"
$Subnet1Name = "Subnet1"
$VNetName = "VNet02"
$VNetAddressPrefix = "10.0.0.0/16"
$VNetSubnetAddressPrefix = "10.0.0.0/24"
## Definiendo Compute
$VMName = "Ubuntu"
$VMSize = "Standard_A1"
$OSDiskName = $VMName + "OSDisk"
#Creando Resource Group
New-AzureRmResourceGroup -Name $ResourceGroupName -Location $Location
# Creando Storage
$StorageAccount = New-AzureRmStorageAccount -ResourceGroupName $ResourceGroupName -Name $StorageName -Type $StorageType -Location $Location
# Creando la Network
$PIp = New-AzureRmPublicIpAddress -Name $InterfaceName -ResourceGroupName $ResourceGroupName -Location $Location -AllocationMethod Dynamic
$SubnetConfig = New-AzureRmVirtualNetworkSubnetConfig -Name $Subnet1Name -AddressPrefix $VNetSubnetAddressPrefix
$VNet = New-AzureRmVirtualNetwork -Name $VNetName -ResourceGroupName $ResourceGroupName -Location $Location -AddressPrefix $VNetAddressPrefix -Subnet $SubnetConfig
$Interface = New-AzureRmNetworkInterface -Name $InterfaceName -ResourceGroupName $ResourceGroupName -Location $Location -SubnetId $VNet.Subnets[0].Id -PublicIpAddressId $PIp.Id
## Definiendo Setup local VM object
$Credential = Get-Credential
$VirtualMachine = New-AzureRmVMConfig -VMName $VMName -VMSize $VMSize
$VirtualMachine = Set-AzureRmVMOperatingSystem -VM $VirtualMachine -ComputerName $VMName -Linux -Credential $Credential
$VirtualMachine = Set-AzureRmVMSourceImage -VM $VirtualMachine -PublisherName "Canonical" -Offer "UbuntuServer" -Skus "16.04-LTS" -Version "latest"
$VirtualMachine = Add-AzureRmVMNetworkInterface -VM $VirtualMachine -Id $Interface.Id
$OSDiskUri = $StorageAccount.PrimaryEndpoints.Blob.ToString() + "vhds/" + $OSDiskName + ".vhd"
$VirtualMachine = Set-AzureRmVMOSDisk -VM $VirtualMachine -Name $OSDiskName -VhdUri $OSDiskUri -CreateOption FromImage
## Creacion de la Virtual Machine Linux en Azure
New-AzureRmVM -ResourceGroupName $ResourceGroupName -Location $Location -VM $VirtualMachine
#Definiendo regla de seguridad de entrada a Virtual Machine
$rule1 = New-AzureRmNetworkSecurityRuleConfig -Name rdp-rule -Description "Allow RDP" -Access Allow -Protocol Tcp -Direction Inbound -Priority 100 -SourceAddressPrefix Internet -SourcePortRange * -DestinationAddressPrefix * -DestinationPortRange 3389
New-AzureRmNetworkSecurityGroup -ResourceGroupName $ResourceGroupName -Location $Location -Name "RSEGURIDAD" -SecurityRules $rule1
#Creando regla de seguridad de entrada a Virtual Machine
New-AzureRmVM -ResourceGroupName $ResourceGroupName -Location $Location -VM $vm
#Comandos para Herramienta Putty para acceso remoto por XRDP
apt-get install xfce4 xrdp
service xrdp status
service xrdp start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment