Skip to content

Commit 1ed91ab

Browse files
committed
Friday morning Checkin: PowerShell deployment
1 parent dbb9ca6 commit 1ed91ab

File tree

5 files changed

+553
-0
lines changed

5 files changed

+553
-0
lines changed

Diff for: CreateNewSQL1.ps1

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Make Initial Connection. Azure Commercial by defultt
2+
# If connecting to Azure Gov, it must be specified.
3+
Connect-AzAccount -EnvironmentName AzureUSGovernment
4+
5+
#Get a list of your subscriptions. If you have more than one, the particular target subscription needs to be set.
6+
#Get-AzSubscription
7+
8+
# If you forget to set the scope (or context) of the Azure PowerSell Az commands to the correct Azure Subscription, then you may end up provisioning or deleting resources in the wrong Azure Subscription
9+
Set-AzContext -SubscriptionName "US Gov FedCon"
10+
11+
# Get a list of Azure Locations so you know which location to add to your globar variable
12+
Get-AzLocation
13+
14+
## Global variables
15+
$Location = "usgovvirginia"
16+
$ResourceGroupName = "rgazsqlvm"
17+
18+
## Storage
19+
$StorageName = $ResourceGroupName + "storage"
20+
$StorageSku = "Premium_LRS"
21+
22+
## Network Properties
23+
$InterfaceName = $ResourceGroupName + "ServerInterface"
24+
$NsgName = $ResourceGroupName + "nsg"
25+
$VNetName = $ResourceGroupName + "VNet"
26+
$SubnetName = "Default"
27+
$VNetAddressPrefix = "10.0.0.0/16"
28+
$VNetSubnetAddressPrefix = "10.0.0.0/24"
29+
$TCPIPAllocationMethod = "Dynamic"
30+
$DomainName = $ResourceGroupName
31+
32+
##Compute
33+
$VMName = $ResourceGroupName + "VM"
34+
$ComputerName = $ResourceGroupName + "Server"
35+
$VMSize = "Standard_DS1_V2"
36+
$OSDiskName = $VMName + "OSDisk"
37+
38+
##Image
39+
$PublisherName = "MicrosoftSQLServer"
40+
$OfferName = "SQL2017-WS2016"
41+
$Sku = "SQLDEV"
42+
$Version = "latest"
43+
44+
# Resource Group
45+
New-AzResourceGroup -Name $ResourceGroupName -Location $Location
46+
47+
# Storage
48+
$StorageAccount = New-AzStorageAccount -ResourceGroupName $ResourceGroupName -Name $StorageName -SkuName $StorageSku -Kind "Storage" -Location $Location
49+
50+
# Network
51+
$SubnetConfig = New-AzVirtualNetworkSubnetConfig -Name $SubnetName -AddressPrefix $VNetSubnetAddressPrefix
52+
$VNet = New-AzVirtualNetwork -Name $VNetName -ResourceGroupName $ResourceGroupName -Location $Location -AddressPrefix $VNetAddressPrefix -Subnet $SubnetConfig
53+
$PublicIp = New-AzPublicIpAddress -Name $InterfaceName -ResourceGroupName $ResourceGroupName -Location $Location -AllocationMethod $TCPIPAllocationMethod -DomainNameLabel $DomainName
54+
$NsgRuleRDP = New-AzNetworkSecurityRuleConfig -Name "RDPRule" -Protocol Tcp -Direction Inbound -Priority 1000 -SourceAddressPrefix * -SourcePortRange * -DestinationAddressPrefix * -DestinationPortRange 3389 -Access Allow
55+
$NsgRuleSQL = New-AzNetworkSecurityRuleConfig -Name "MSSQLRule" -Protocol Tcp -Direction Inbound -Priority 1001 -SourceAddressPrefix * -SourcePortRange * -DestinationAddressPrefix * -DestinationPortRange 1433 -Access Allow
56+
$Nsg = New-AzNetworkSecurityGroup -ResourceGroupName $ResourceGroupName -Location $Location -Name $NsgName -SecurityRules $NsgRuleRDP,$NsgRuleSQL
57+
$Interface = New-AzNetworkInterface -Name $InterfaceName -ResourceGroupName $ResourceGroupName -Location $Location -SubnetId $VNet.Subnets[0].Id -PublicIpAddressId $PublicIp.Id -NetworkSecurityGroupId $Nsg.Id
58+
59+
# Compute
60+
$VirtualMachine = New-AzVMConfig -VMName $VMName -VMSize $VMSize
61+
$Credential = Get-Credential -Message "Type the name and password of the local administrator account."
62+
$VirtualMachine = Set-AzVMOperatingSystem -VM $VirtualMachine -Windows -ComputerName $ComputerName -Credential $Credential -ProvisionVMAgent -EnableAutoUpdate #-TimeZone = $TimeZone
63+
$VirtualMachine = Add-AzVMNetworkInterface -VM $VirtualMachine -Id $Interface.Id
64+
$OSDiskUri = $StorageAccount.PrimaryEndpoints.Blob.ToString() + "vhds/" + $OSDiskName + ".vhd"
65+
$VirtualMachine = Set-AzVMOSDisk -VM $VirtualMachine -Name $OSDiskName -VhdUri $OSDiskUri -Caching ReadOnly -CreateOption FromImage
66+
67+
# Image
68+
$VirtualMachine = Set-AzVMSourceImage -VM $VirtualMachine -PublisherName $PublisherName -Offer $OfferName -Skus $Sku -Version $Version
69+
70+
# Create the VM in Azure
71+
New-AzVM -ResourceGroupName $ResourceGroupName -Location $Location -VM $VirtualMachine
72+
73+
# Add the SQL IaaS Extension, and choose the license type
74+
New-AzSqlVM -ResourceGroupName $ResourceGroupName -Name $VMName -Location $Location -LicenseType PAYG

Diff for: CreateSQLonAzureVM.ps1

Whitespace-only changes.
Loading

0 commit comments

Comments
 (0)