Guest User

Untitled

a guest
Dec 19th, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.76 KB | None | 0 0
  1. # Create variables to store the location and resource group names.
  2. $location = "<location azure stack>"
  3. $ResourceGroupName = "RG-IMG-WS-TEST"
  4.  
  5. New-AzureRmResourceGroup `
  6. -Name $ResourceGroupName `
  7. -Location $location
  8.  
  9. # Create variables to store the storage account name and the storage account SKU information
  10. $StorageAccountName = "rgimgwstest"
  11. $SkuName = "Standard_LRS"
  12.  
  13. # Create a new storage account
  14. $StorageAccount = New-AzureRMStorageAccount `
  15. -Location $location `
  16. -ResourceGroupName $ResourceGroupName `
  17. -Type $SkuName `
  18. -Name $StorageAccountName
  19.  
  20. Set-AzureRmCurrentStorageAccount `
  21. -StorageAccountName $storageAccountName `
  22. -ResourceGroupName $resourceGroupName
  23.  
  24. # Create a storage container to store the virtual machine image
  25. $containerName = 'osdisks'
  26. $container = New-AzureStorageContainer `
  27. -Name $containerName `
  28. -Permission Blob
  29.  
  30. # Create a subnet configuration
  31. $subnetConfig = New-AzureRmVirtualNetworkSubnetConfig `
  32. -Name InternalSubnet `
  33. -AddressPrefix 192.168.1.0/24
  34.  
  35. # Create a virtual network
  36. $vnet = New-AzureRmVirtualNetwork `
  37. -ResourceGroupName $ResourceGroupName `
  38. -Location $location `
  39. -Name Vnet `
  40. -AddressPrefix 192.168.0.0/16 `
  41. -Subnet $subnetConfig
  42.  
  43. # Create a public IP address and specify a DNS name
  44. $pip = New-AzureRmPublicIpAddress `
  45. -ResourceGroupName $ResourceGroupName `
  46. -Location $location `
  47. -AllocationMethod Static `
  48. -IdleTimeoutInMinutes 4 `
  49. -Name "imgippublic$(Get-Random)"
  50.  
  51. # Create an inbound network security group rule for port 3389
  52. $nsgRuleRDP = New-AzureRmNetworkSecurityRuleConfig `
  53. -Name RuleRDP `
  54. -Protocol Tcp `
  55. -Direction Inbound `
  56. -Priority 1000 `
  57. -SourceAddressPrefix * `
  58. -SourcePortRange * `
  59. -DestinationAddressPrefix * `
  60. -DestinationPortRange 3389 `
  61. -Access Allow
  62.  
  63. # Create an inbound network security group rule for port 80
  64. $nsgRuleWeb = New-AzureRmNetworkSecurityRuleConfig `
  65. -Name RuleWWW `
  66. -Protocol Tcp `
  67. -Direction Inbound `
  68. -Priority 1001 `
  69. -SourceAddressPrefix * `
  70. -SourcePortRange * `
  71. -DestinationAddressPrefix * `
  72. -DestinationPortRange 80 `
  73. -Access Allow
  74.  
  75. # Create a network security group
  76. $nsg = New-AzureRmNetworkSecurityGroup `
  77. -ResourceGroupName $ResourceGroupName `
  78. -Location $location `
  79. -Name IMG-WS-NSG `
  80. -SecurityRules $nsgRuleRDP,$nsgRuleWeb
  81.  
  82. # Create a virtual network card and associate it with public IP address and NSG
  83. $nic = New-AzureRmNetworkInterface `
  84. -Name IMG-WS-NIC `
  85. -ResourceGroupName $ResourceGroupName `
  86. -Location $location `
  87. -SubnetId $vnet.Subnets[0].Id `
  88. -PublicIpAddressId $pip.Id `
  89. -NetworkSecurityGroupId $nsg.Id
  90.  
  91. # Define a credential object to store the username and password for the virtual machine
  92. $UserName='demouser'
  93. $Password='Password@123'| ConvertTo-SecureString -Force -AsPlainText
  94. $Credential=New-Object PSCredential($UserName,$Password)
  95.  
  96. # Create the virtual machine configuration object
  97. $VmName = "WS2012R2STD"
  98. $VmSize = "Standard_D2_v2"
  99. $VirtualMachine = New-AzureRmVMConfig `
  100. -VMName $VmName `
  101. -VMSize $VmSize
  102.  
  103. $VirtualMachine = Set-AzureRmVMOperatingSystem `
  104. -VM $VirtualMachine `
  105. -Windows `
  106. -ComputerName "WS2012R2STD" `
  107. -Credential $Credential
  108.  
  109. $urlOfImageVhd = "<url location vhd file in container blob>"
  110.  
  111. #Create the OS disk URI
  112. $osDiskName = "OsDisk"
  113. $osDiskUri = '{0}vhds/{1}-{2}.vhd' -f `
  114. $StorageAccount.PrimaryEndpoints.Blob.ToString(),`
  115. $vmName.ToLower(), `
  116. $osDiskName
  117.  
  118. # Sets the operating system disk properties on a virtual machine.
  119. $VirtualMachine = Set-AzureRmVMOSDisk `
  120. -VM $VirtualMachine `
  121. -Name $osDiskName `
  122. -VhdUri $OsDiskUri `
  123. -CreateOption FromImage -SourceImageUri $urlOfImageVhd -Windows | Add-AzureRmVMNetworkInterface -Id $nic.Id
  124.  
  125. #Create the virtual machine.
  126. New-AzureRmVM `
  127. -ResourceGroupName $ResourceGroupName `
  128. -Location $location `
  129. -VM $VirtualMachine -Verbose
Add Comment
Please, Sign In to add comment