Skip to content

Instantly share code, notes, and snippets.

@imartinezm
Last active May 15, 2017 02:23
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/0db81bc3321f90c5d2bb003428511ba6 to your computer and use it in GitHub Desktop.
Save imartinezm/0db81bc3321f90c5d2bb003428511ba6 to your computer and use it in GitHub Desktop.
Creacion Virtual Machine PowerShellAzure
# Declaracion de Variables
## Grupo de Recursos
$ResourceGroupName = "ResourceGroupPeru"
$Location = "WestEurope"
## Almacenamiento
$StorageName = "resourcestorage1"
$StorageType = "Standard_GRS"
## Red
$InterfaceName = "ServerInterface01"
$Subnet1Name = "Subnet1"
$VNetName = "VNet02"
$VNetAddressPrefix = "10.0.0.0/16"
$VNetSubnetAddressPrefix = "10.0.0.0/24"
## Virtual Machine
$VMName = "VirtualMachine12"
$ComputerName = "Server22"
$VMSize = "Standard_A2"
$OSDiskName = $VMName + "OSDisk"
## Creacion de Servicios Azure
## Grupo de Recursos
New-AzureRmResourceGroup -Name $ResourceGroupName -Location $Location
# Cuenta de Almacenamiento
$StorageAccount = New-AzureRmStorageAccount -ResourceGroupName $ResourceGroupName -Name $StorageName -Type $StorageType -Location $Location
$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
## Configuracion local Virtual Machine
$Credential = Get-Credential
$VirtualMachine = New-AzureRmVMConfig -VMName $VMName -VMSize $VMSize
$VirtualMachine = Set-AzureRmVMOperatingSystem -VM $VirtualMachine -Windows -ComputerName $ComputerName -Credential $Credential -ProvisionVMAgent -EnableAutoUpdate
$VirtualMachine = Set-AzureRmVMSourceImage -VM $VirtualMachine -PublisherName MicrosoftWindowsServer -Offer WindowsServer -Skus 2012-R2-Datacenter -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
New-AzureRmVM -ResourceGroupName $ResourceGroupName -Location $Location -VM $VirtualMachine
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment