Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <#
- Script Name: New-IaasInfrastructure.ps1
- Created by: Robert Danielsson - CGI
- Mail: robert.danielsson@cgi.com
- Last modified: 2017-03-29
- Ver: 1.3
- 1.1 Added KeyVault creation
- 1.2 Added NSG creation
- 1.3 Added OnPrem fileshare
- 1.3 Added DomainJoin variables
- This script creates the components that are required for Azure Managed Service
- This script should only be run at first implementation.
- #>
- ##############################################################################################################
- # Below is the variables that you must change to fit the customer
- #
- ##############################################################################################################
- $Location = "West Europe" # Where do you want to deploy the solution
- $Customer= "customername" # Customer name, use lowercase and no åäö
- $vNetPref="10.1.0.0/16" # Virtual Network Adress space, use CIDR notation
- $SubnetIPAdrPref="10.1.0.0/24" # Subnet IP range, use CIDR notation. If you want to change subnetname, change the $subnetName parameter below.
- $OnPremFShare= '\\Server\Share'# FileShare onprem or in Azure that holds the installation files for MC, .Net etc
- $DomainName= 'YOURDOMAIN.LOCAL' # Enter the default domain that domain servers should be installed in.
- $DomainUser= 'FILL_IN' # Enter a user that has access to joinin machines to the domain.
- $DomainUserPW= 'FILL_IN' # Enter the PW for the user , ensure that you do not save this script with Domain User
- ##############################################################################################################
- ##############################################################################################################
- #
- # MAIN Script
- #
- # Dont change this variables unless you know what you do
- #
- ##############################################################################################################
- CLS
- $str=$Customer
- if ($str -cmatch "^[a-z]*$") {Write-Host "Customer Name is OK"}
- else {write-host "Customer name contains illegal characters, Exiting Script"
- Exit
- }
- # Defining Variables for Assets in Azure Portal CGI specific
- $assAutomation = $customer+"AutoAcc"
- $assDefaultLocation =$Location
- $assCustomer=$Customer
- $assStorageContainer="logs"
- $assStorageContainer2="files"
- $assDefResGroup=$Customer+"01"
- $BupVaultName = $Customer+"BupV01"
- $assBupVault = $BupVaultName
- $BackupStgRedundancy="GeoRedundant"
- $BupPolicyName=$Customer+"Policy01"
- $vNetName=$Customer +"-vnet01"
- $subnetName=$Customer +"-internal01"
- $assDefOperationStorage=$customer + "opstg"
- $int=1
- $KeyVaultName=$Customer +"-KeyV"
- Write-Host "Login to Azure" -ForegroundColor Yellow
- Login-AzureRmAccount
- $Subscription = Get-AzureRmSubscription | Out-GridView -Title "Choose Subscription" -PassThru
- Select-AzureRmSubscription -SubscriptionName $Subscription.SubscriptionName
- # Creates AutomationAccount and Storage / Resource group
- Write-Host "Creates AutomationAccount and Storage / Resource group"
- New-AzureRmResourceGroup -Name $assDefResGroup -Location $assDefaultLocation
- New-AzureRmAutomationAccount -ResourceGroupName $assDefResGroup -Location $Location -Name $assAutomation
- New-AzureRmStorageAccount -ResourceGroupName $assDefResGroup -Name $assDefOperationStorage -SkuName:Standard_LRS -Location $assDefaultLocation
- Set-AzureRmCurrentStorageAccount -ResourceGroupName $assDefResGroup -Name $assDefOperationStorage
- New-AzureStorageContainer -Name $assStorageContainer
- New-AzureStorageContainer -Name $assStorageContainer2
- # Create Azureautomation Variables
- Write-host "Create Azureautomation Variables"
- New-AzurermAutomationVariable -Name "DefaultLocation" -Value $assDefaultLocation -ResourceGroupName $assDefResGroup -AutomationAccountName $assAutomation -Encrypted $False
- New-AzurermAutomationVariable -Name "DefaultResGroup" -Value $assDefResGroup -ResourceGroupName $assDefResGroup -AutomationAccountName $assAutomation -Encrypted $False
- New-AzureRmAutomationVariable -Name "DefaultRecVault" -Value $BupVaultName -ResourceGroupName $assDefResGroup -AutomationAccountName $assAutomation -Encrypted $False
- New-AzureRmAutomationVariable -Name "StorageCount" -Value $int -ResourceGroupName $assDefResGroup -AutomationAccountName $assAutomation -Encrypted $False
- New-AzureRmAutomationVariable -Name "Customer" -Value $Customer -ResourceGroupName $assDefResGroup -AutomationAccountName $assAutomation -Encrypted $False
- New-AzureRmAutomationVariable -Name "Fileshare" -Value $OnPremFShare -ResourceGroupName $assDefResGroup -AutomationAccountName $assAutomation -Encrypted $False
- New-AzureRmAutomationVariable -Name "DomainName" -Value $DomainName -ResourceGroupName $assDefResGroup -AutomationAccountName $assAutomation -Encrypted $False
- # Fetch the Automation Asset Variable
- Write-Host "Fetch Azureautomation Variables"
- $rsgr=Get-AzureRmAutomationVariable -Name DefaultResGroup -ResourceGroupName $assDefResGroup -AutomationAccountName $assAutomation
- $loc=Get-AzureRmAutomationVariable -Name DefaultLocation -ResourceGroupName $assDefResGroup -AutomationAccountName $assAutomation
- # Creating Vnet and Subnet
- Write-Host "Creating VNet. Subnet and Network Security Groups"
- $subnet=New-AzureRmVirtualNetworkSubnetConfig -Name $subnetName -AddressPrefix $SubnetIPAdrPref
- $vNet=New-AzureRmVirtualNetwork -Name $vNetName -ResourceGroupName $rsgr.Value -Location $loc.Value -AddressPrefix $vNetPref -Subnet $subnet
- # Create first NSG Rule
- $nsg = New-AzureRmNetworkSecurityGroup -ResourceGroupName $rsgr.Value -Location $loc.Value -Name "DefaultRule"
- # Associate the NSG created above to the subnet.
- Set-AzureRmVirtualNetworkSubnetConfig -VirtualNetwork $vnet -Name $subnetName `
- -AddressPrefix $SubnetIPAdrPref -NetworkSecurityGroup $nsg
- # Save Networkchanges
- Set-AzureRmVirtualNetwork -VirtualNetwork $vnet
- # Creating BackupVault and Policy
- Write-host "Creating Backup Vault and Policy"
- $rec=Get-AzureRmAutomationVariable -Name DefaultRecVault -ResourceGroupName $assDefResGroup -AutomationAccountName $assAutomation
- $vault=New-AzureRmRecoveryServicesVault -Name $rec.Value -ResourceGroupName $rsgr.Value -Location $loc.Value
- Set-AzureRmSiteRecoveryVaultSettings -ARSVault $vault
- Set-AzureRmRecoveryServicesBackupProperties -Vault $vault -BackupStorageRedundancy $BackupStgRedundancy
- # Creating Key Vault
- Write-host "Creating Key Vault"
- New-AzureRmKeyVault -VaultName $KeyVaultName -ResourceGroupName $rsgr.Value -Location $loc.Value -Sku Standard
- cls
- Write-Host "Script Done, now you can provision machine"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement