Last active
May 15, 2017 02:23
-
-
Save imartinezm/0db81bc3321f90c5d2bb003428511ba6 to your computer and use it in GitHub Desktop.
Creacion Virtual Machine PowerShellAzure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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