Skip to content

Instantly share code, notes, and snippets.

@m-moris
Last active August 29, 2015 14:24
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 m-moris/e9a858b2f5753e0d6fe3 to your computer and use it in GitHub Desktop.
Save m-moris/e9a858b2f5753e0d6fe3 to your computer and use it in GitHub Desktop.
#
# Azure PowerShell ARM モードで仮想マシン V2を作成するサンプル
#
Switch-AzureMode -Name AzureResourceManager
#
$rg = "someResourceGroup"
$loc = "someLocation"
$storage = "someStorage"
$domain = "someDomain"
$osDisk = "https://{0}.blob.core.windows.net/vhds/OsDisk.vhd" -f $storage
$vmName = "myUbuntu"
$computerName = "myUbuntu"
$nicName = "myNic"
$subnetName = "Subnet-1"
$vnetName = "myVnet"
$vnetPrefix = "10.0.0.0/8"
$subnetPrefix = "10.0.0.0/24"
$privateIpAddress = "10.0.0.10"
# リソースグループの作成
New-AzureResourceGroup -Name $rg -Location $loc
# ストレージアカウント LRSで作成
New-AzureStorageAccount -ResourceGroupName $rg -Location $loc `
-Name $storage -Type Standard_LRS
# パブリックIPアドレスの作成
$ip = New-AzurePublicIpAddress -ResourceGroupName $rg -Location $loc `
-Name myPublicIp -AllocationMethod Dynamic -DomainNameLabel $domain
# サブネットの作成
$subnet = New-AzureVirtualNetworkSubnetConfig -Name $subnetName -AddressPrefix $subnetPrefix
$vnet = New-AzureVirtualNetwork -ResourceGroupName $rg -Location $loc `
-Name $vnetName -AddressPrefix $vnetPrefix -Subnet $subnet
$subnet = Get-AzureVirtualNetworkSubnetConfig -Name $subnetName -VirtualNetwork $vnet
# ネットワークインタフェースの作成
$nic = New-AzureNetworkInterface -ResourceGroupName $rg -Location $loc `
-Name $nicName -PrivateIpAddress $privateIpAddress -Subnet $subnet -PublicIpAddress $ip
# User/Passwordの設定
$creds = Get-Credential
# VMの構成 Ubuntu 14.04-LTS
$config = `
New-AzureVMConfig -VMName $vmName -VMSize Standard_A1 |
Set-AzureVMOperatingSystem -Linux -ComputerName myUbuntu -Credential $creds |
Set-AzureVMSourceImage -PublisherName canonical -Offer UbuntuServer -Skus 14.04.2-LTS -Version 14.04.201506100 |
Set-AzureVMOSDisk -Name "ubuntuOsDisk" -CreateOption fromImage -Caching ReadWrite -VhdUri $osDisk |
Add-AzureVMNetworkInterface -Id $nic.Id
# VMの作成
New-AzureVM -ResourceGroupName $rg -Location $loc -VM $config -Name $vmName
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment