Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Create variables to store the location and resource group names.
- $location = "<location azure stack>"
- $ResourceGroupName = "RG-IMG-WS-TEST"
- New-AzureRmResourceGroup `
- -Name $ResourceGroupName `
- -Location $location
- # Create variables to store the storage account name and the storage account SKU information
- $StorageAccountName = "rgimgwstest"
- $SkuName = "Standard_LRS"
- # Create a new storage account
- $StorageAccount = New-AzureRMStorageAccount `
- -Location $location `
- -ResourceGroupName $ResourceGroupName `
- -Type $SkuName `
- -Name $StorageAccountName
- Set-AzureRmCurrentStorageAccount `
- -StorageAccountName $storageAccountName `
- -ResourceGroupName $resourceGroupName
- # Create a storage container to store the virtual machine image
- $containerName = 'osdisks'
- $container = New-AzureStorageContainer `
- -Name $containerName `
- -Permission Blob
- # Create a subnet configuration
- $subnetConfig = New-AzureRmVirtualNetworkSubnetConfig `
- -Name InternalSubnet `
- -AddressPrefix 192.168.1.0/24
- # Create a virtual network
- $vnet = New-AzureRmVirtualNetwork `
- -ResourceGroupName $ResourceGroupName `
- -Location $location `
- -Name Vnet `
- -AddressPrefix 192.168.0.0/16 `
- -Subnet $subnetConfig
- # Create a public IP address and specify a DNS name
- $pip = New-AzureRmPublicIpAddress `
- -ResourceGroupName $ResourceGroupName `
- -Location $location `
- -AllocationMethod Static `
- -IdleTimeoutInMinutes 4 `
- -Name "imgippublic$(Get-Random)"
- # Create an inbound network security group rule for port 3389
- $nsgRuleRDP = New-AzureRmNetworkSecurityRuleConfig `
- -Name RuleRDP `
- -Protocol Tcp `
- -Direction Inbound `
- -Priority 1000 `
- -SourceAddressPrefix * `
- -SourcePortRange * `
- -DestinationAddressPrefix * `
- -DestinationPortRange 3389 `
- -Access Allow
- # Create an inbound network security group rule for port 80
- $nsgRuleWeb = New-AzureRmNetworkSecurityRuleConfig `
- -Name RuleWWW `
- -Protocol Tcp `
- -Direction Inbound `
- -Priority 1001 `
- -SourceAddressPrefix * `
- -SourcePortRange * `
- -DestinationAddressPrefix * `
- -DestinationPortRange 80 `
- -Access Allow
- # Create a network security group
- $nsg = New-AzureRmNetworkSecurityGroup `
- -ResourceGroupName $ResourceGroupName `
- -Location $location `
- -Name IMG-WS-NSG `
- -SecurityRules $nsgRuleRDP,$nsgRuleWeb
- # Create a virtual network card and associate it with public IP address and NSG
- $nic = New-AzureRmNetworkInterface `
- -Name IMG-WS-NIC `
- -ResourceGroupName $ResourceGroupName `
- -Location $location `
- -SubnetId $vnet.Subnets[0].Id `
- -PublicIpAddressId $pip.Id `
- -NetworkSecurityGroupId $nsg.Id
- # Define a credential object to store the username and password for the virtual machine
- $UserName='demouser'
- $Password='Password@123'| ConvertTo-SecureString -Force -AsPlainText
- $Credential=New-Object PSCredential($UserName,$Password)
- # Create the virtual machine configuration object
- $VmName = "WS2012R2STD"
- $VmSize = "Standard_D2_v2"
- $VirtualMachine = New-AzureRmVMConfig `
- -VMName $VmName `
- -VMSize $VmSize
- $VirtualMachine = Set-AzureRmVMOperatingSystem `
- -VM $VirtualMachine `
- -Windows `
- -ComputerName "WS2012R2STD" `
- -Credential $Credential
- $urlOfImageVhd = "<url location vhd file in container blob>"
- #Create the OS disk URI
- $osDiskName = "OsDisk"
- $osDiskUri = '{0}vhds/{1}-{2}.vhd' -f `
- $StorageAccount.PrimaryEndpoints.Blob.ToString(),`
- $vmName.ToLower(), `
- $osDiskName
- # Sets the operating system disk properties on a virtual machine.
- $VirtualMachine = Set-AzureRmVMOSDisk `
- -VM $VirtualMachine `
- -Name $osDiskName `
- -VhdUri $OsDiskUri `
- -CreateOption FromImage -SourceImageUri $urlOfImageVhd -Windows | Add-AzureRmVMNetworkInterface -Id $nic.Id
- #Create the virtual machine.
- New-AzureRmVM `
- -ResourceGroupName $ResourceGroupName `
- -Location $location `
- -VM $VirtualMachine -Verbose
Add Comment
Please, Sign In to add comment