Advertisement
Guest User

Untitled

a guest
Mar 29th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. <#
  3. Script Name: New-IaasInfrastructure.ps1
  4. Created by: Robert Danielsson - CGI
  5. Mail: robert.danielsson@cgi.com
  6. Last modified: 2017-03-29
  7. Ver: 1.3
  8.  
  9. 1.1 Added KeyVault creation
  10. 1.2 Added NSG creation
  11. 1.3 Added OnPrem fileshare
  12. 1.3 Added DomainJoin variables
  13.  
  14. This script creates the components that are required for Azure Managed Service
  15. This script should only be run at first implementation.
  16. #>
  17. ##############################################################################################################
  18. # Below is the variables that you must change to fit the customer
  19. #
  20. ##############################################################################################################
  21.  
  22. $Location = "West Europe" # Where do you want to deploy the solution
  23. $Customer= "customername" # Customer name, use lowercase and no åäö
  24. $vNetPref="10.1.0.0/16" # Virtual Network Adress space, use CIDR notation
  25. $SubnetIPAdrPref="10.1.0.0/24" # Subnet IP range, use CIDR notation. If you want to change subnetname, change the $subnetName parameter below.
  26. $OnPremFShare= '\\Server\Share'# FileShare onprem or in Azure that holds the installation files for MC, .Net etc
  27. $DomainName= 'YOURDOMAIN.LOCAL' # Enter the default domain that domain servers should be installed in.
  28. $DomainUser= 'FILL_IN' # Enter a user that has access to joinin machines to the domain.
  29. $DomainUserPW= 'FILL_IN' # Enter the PW for the user , ensure that you do not save this script with Domain User
  30.  
  31. ##############################################################################################################
  32.  
  33.  
  34. ##############################################################################################################
  35. #
  36. #                             MAIN Script
  37. #
  38. #                           Dont change this variables unless you know what you do
  39. #
  40. ##############################################################################################################
  41. CLS
  42. $str=$Customer
  43. if ($str -cmatch "^[a-z]*$") {Write-Host "Customer Name is OK"}
  44. else {write-host "Customer name contains illegal characters, Exiting Script"
  45. Exit
  46. }
  47.  
  48. # Defining Variables for Assets in Azure Portal CGI specific
  49. $assAutomation = $customer+"AutoAcc"
  50. $assDefaultLocation =$Location
  51. $assCustomer=$Customer
  52. $assStorageContainer="logs"
  53. $assStorageContainer2="files"
  54. $assDefResGroup=$Customer+"01"
  55. $BupVaultName = $Customer+"BupV01"
  56. $assBupVault = $BupVaultName
  57. $BackupStgRedundancy="GeoRedundant"
  58. $BupPolicyName=$Customer+"Policy01"
  59. $vNetName=$Customer +"-vnet01"
  60. $subnetName=$Customer +"-internal01"
  61. $assDefOperationStorage=$customer + "opstg"
  62. $int=1
  63. $KeyVaultName=$Customer +"-KeyV"
  64. Write-Host "Login to Azure" -ForegroundColor Yellow
  65. Login-AzureRmAccount
  66. $Subscription = Get-AzureRmSubscription | Out-GridView -Title "Choose Subscription" -PassThru
  67. Select-AzureRmSubscription -SubscriptionName $Subscription.SubscriptionName
  68.  
  69. # Creates AutomationAccount and Storage / Resource group
  70. Write-Host "Creates AutomationAccount and Storage / Resource group"
  71. New-AzureRmResourceGroup -Name $assDefResGroup -Location $assDefaultLocation
  72. New-AzureRmAutomationAccount -ResourceGroupName $assDefResGroup -Location $Location -Name $assAutomation
  73. New-AzureRmStorageAccount -ResourceGroupName $assDefResGroup -Name $assDefOperationStorage -SkuName:Standard_LRS -Location $assDefaultLocation
  74. Set-AzureRmCurrentStorageAccount -ResourceGroupName $assDefResGroup -Name $assDefOperationStorage
  75. New-AzureStorageContainer -Name $assStorageContainer
  76. New-AzureStorageContainer -Name $assStorageContainer2
  77.  
  78. # Create Azureautomation Variables
  79. Write-host "Create Azureautomation Variables"
  80. New-AzurermAutomationVariable -Name "DefaultLocation" -Value $assDefaultLocation -ResourceGroupName $assDefResGroup -AutomationAccountName $assAutomation -Encrypted $False
  81. New-AzurermAutomationVariable -Name "DefaultResGroup" -Value $assDefResGroup  -ResourceGroupName $assDefResGroup -AutomationAccountName $assAutomation -Encrypted $False
  82. New-AzureRmAutomationVariable -Name "DefaultRecVault" -Value $BupVaultName -ResourceGroupName $assDefResGroup -AutomationAccountName $assAutomation -Encrypted $False
  83. New-AzureRmAutomationVariable -Name "StorageCount" -Value $int -ResourceGroupName $assDefResGroup -AutomationAccountName $assAutomation -Encrypted $False
  84. New-AzureRmAutomationVariable -Name "Customer" -Value $Customer -ResourceGroupName $assDefResGroup -AutomationAccountName $assAutomation -Encrypted $False
  85. New-AzureRmAutomationVariable -Name "Fileshare" -Value $OnPremFShare -ResourceGroupName $assDefResGroup -AutomationAccountName $assAutomation -Encrypted $False
  86. New-AzureRmAutomationVariable -Name "DomainName" -Value $DomainName -ResourceGroupName $assDefResGroup -AutomationAccountName $assAutomation -Encrypted $False
  87.  
  88.  
  89. # Fetch the Automation Asset Variable
  90. Write-Host "Fetch Azureautomation Variables"
  91. $rsgr=Get-AzureRmAutomationVariable -Name DefaultResGroup -ResourceGroupName $assDefResGroup -AutomationAccountName $assAutomation
  92. $loc=Get-AzureRmAutomationVariable -Name DefaultLocation -ResourceGroupName $assDefResGroup -AutomationAccountName $assAutomation
  93.  
  94. # Creating Vnet and Subnet
  95. Write-Host "Creating VNet. Subnet and Network Security Groups"
  96. $subnet=New-AzureRmVirtualNetworkSubnetConfig -Name $subnetName -AddressPrefix $SubnetIPAdrPref
  97. $vNet=New-AzureRmVirtualNetwork -Name $vNetName -ResourceGroupName $rsgr.Value -Location $loc.Value -AddressPrefix $vNetPref -Subnet $subnet
  98.  
  99. # Create first NSG Rule
  100. $nsg = New-AzureRmNetworkSecurityGroup -ResourceGroupName $rsgr.Value -Location $loc.Value -Name "DefaultRule"
  101.  
  102. # Associate the NSG created above to the  subnet.
  103.  Set-AzureRmVirtualNetworkSubnetConfig -VirtualNetwork $vnet -Name $subnetName `
  104.  -AddressPrefix $SubnetIPAdrPref -NetworkSecurityGroup $nsg
  105.  
  106. # Save Networkchanges
  107. Set-AzureRmVirtualNetwork -VirtualNetwork $vnet
  108.  
  109. # Creating BackupVault and Policy
  110. Write-host "Creating Backup Vault and Policy"
  111. $rec=Get-AzureRmAutomationVariable -Name DefaultRecVault -ResourceGroupName $assDefResGroup -AutomationAccountName $assAutomation
  112. $vault=New-AzureRmRecoveryServicesVault -Name $rec.Value -ResourceGroupName $rsgr.Value -Location $loc.Value
  113. Set-AzureRmSiteRecoveryVaultSettings -ARSVault $vault
  114. Set-AzureRmRecoveryServicesBackupProperties  -Vault $vault -BackupStorageRedundancy $BackupStgRedundancy
  115.  
  116. # Creating Key Vault
  117. Write-host "Creating Key Vault"
  118. New-AzureRmKeyVault -VaultName $KeyVaultName -ResourceGroupName $rsgr.Value -Location $loc.Value -Sku Standard
  119. cls
  120. Write-Host "Script Done, now you can provision machine"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement