New MRVAzureVM - mrvladis/mrv_module GitHub Wiki
.Synopsis
Script to create a VM (s) in Azure according stardards and perfporm after deployment tasks.
Description
Script will connect to the closet domain controller to perform any AD related activities. Domain controllers returned as part of the subscription selection.
Please customise Select-MRVSubscription to specify relevant AD DS Servers. Note! Cmdlet require ARM Templates to be stored in the module folder.
- Organizational Unit (OU) corresponding to the Resource Group name will be created under OU specified in AzureServersBaseOU parameter if it does not exist
- WinRM will be configured on the server to run on port 5986 with self-signed certificate.
- Data disk will be provisioned if has not been excluded during provisioning. Script will check for RAW partitions and hey will be initialised, formatted and Disk Drives will be assigned.
- Any CD/DVD drives will be moved to Drive Letter O and further.
- Time zone will be set to "GMT Standard Time"
Prequisites
* AzureRM or AzureRM.Netcore Module.
* Azure CLI 2.0 required to provide cross patform compatibility.
Limitations
* If executed from none-Windows environement any Active Directory actions will be skipped as Active Directory cmdlets are currently unavailable from Linux or MacOS.
Change Log
v.1.0.0.0 - Moved history of the changes here
Backlog
AttachDataVHDs - need to be added with the support of managed disks. Backup - add vm to Azure Backup upon creation.
Syntax:
Function has the following parameters:
.Parameter VMname
Name for the Virtual Machine that will be used to represent the VM in Azure and used as a Computer name. Should be formatted according to the Naming Convention.
.Parameter ResourceGroupName
Name for the Resource Group that will represent the service within the Azure and contain all the service elements. Should be formatted according to the Naming Convention.
.Parameter SubscriptionName
Used to specify the subscription that the VM belongs to.
.Parameter Prefix_Main
Prefix that is used for all objects that got created as part of the deployment.
.Parameter VMIPaddresses
Specifies the IP addresses that is going to be used by VM. Can Accept one or multiple comma separated values. Examples: -VMIPaddresses “192.168.0.1” or -VMIPaddresses “192.168.0.1, 192.168.0.2, 192.168.0.3” Note! If supplying multiple IP addresses - IfaceCount parameter should be used and provide the number of IP addresses. Script will look for the Virtual Networks and their subnets to identify it based on the IP address. Note! Subnet should be created before trying to provision VM. Scrip will verify that IP address is free to use.
.Parameter ChangeControl
Reference to the Change Control in Service Now that has been raised to provision the VM.
.Parameter Description
Text Description that will be helpful to identify the provisioned VM. You can receive the following error during such a deployment: “New-AzureRmResourceGroupDeployment : 11:59:31 AM - Creating a virtual machine from Marketplace image requires Plan information in the request. OS disk name is mrv-sh-hi-001-osdisk.” Note! Use this switch to try to deploy with the default Plan.
.Parameter VMSize
Size of the Azure VM. Must be one of the standard values.
.Parameter ASID
Availability Set ID. Should be provided in format XX where X is any number.
.Parameter IfaceCount
Number of the Network Interfaces that needed for the VM. Note! If IfaceCount used and values id more than 1 - multiple IP addresses need to be supplied in VMIPaddresses parameter. Note! VM should meet the requirements for the Multi-Interface VM.
.Parameter StorageAccountType
Can be used to override default value: Standard_LRS (Locally Redundant) Can be one of the following values: 'Standard_LRS', 'Standard_GRS', 'Premium_LRS', 'Standard_RAGRS'
.Parameter StorageDiagAccountName
Storage Account name that will be used to store Azure Diagnostics. Storage account need to be in the same Azure Region as VM that is going to be deployed. If not defined - Script will check for storage account with tag "Purpose" that has value "AzureDiagnostics". If there is nothing found - script will attempt to create one.
.Parameter Override
Use this option to override any existing deployment.
.Parameter StandaloneVM
VM will be deployed as standalone. It will not be joined to the domain and no access groups will be created.
.Parameter SourceVM
Virtual machine name (Short name, eg MRV-SH-MGMT-001) should be provided. Note! VM should be accessible from the server script is running on ports 5985 and 5986 (Remote WMI)
.Parameter SourceXML
Same logic ad with the SourceVm, but Roles and Features XML need to be prepared first.
.Parameter Simulate
This parameter is used to go through the parameters population and validation, but will skip any deployment. Meanwhile, the deployment configuration will still be uploaded to Azure Blob Storage.
.Parameter ManagedDisks
This is a switch to use if VM need to be deployed with Managed Disks.
.Parameter UseExistingDisk
Used to create a Virtual Machine from the existing VHD disk. Disk should be placed in to the proper storage account (according to the parameters you are using during the deployment) and be named properly. Note! You can use “-simulate” to check for the proper names of the system disk and storage account name! Simulation will also create the Resource Group if it does not exist before. Note! Storage account need to be created in the Resource Group before copying the VHD. Use ARM_Copy_VHD to perform the copy of the VM VHD disks. Note! Virtual Machine will be provisioned without data disks! They need to be attached later manually! Note! Some provisioning steps will be skipped due to the fact that VM will be created from the existing one.
.Parameter ImageSKU
You can specify SKU you want to use for the deployment. "2012-R2-Datacenter" used by default. Please see below for details.
.Parameter imagePublisher
You can specify Publisher you want to use for the deployment. "MicrosoftWindowsServer" used by default. Please see below for details.
.Parameter imageOffer
You can specify Offer you want to use for the deployment. "WindowsServer" used by default. Please see below for details. Note! $loc – Azure Location (Get-AzureRMLocations) $loc = "northeurope" #Find all the available publishers Get-AzureRMVMImagePublisher -Location $loc | Select PublisherName #Pick a publisher $pubName="MicrosoftWindowsServer" #Get available offers Get-AzureRMVMImageOffer -Location $loc -Publisher $pubName | Select Offer #Pick a specific offer $offerName="WindowsServer" #View the different SKUs Get-AzureRMVMImageSku -Location $loc -Publisher $pubName -Offer $offerName | Select Skus #Pick a SKU $skuName="2016-Datacenter" #View the versions of a SKU Get-AzureRMVMImage -Location $loc -PublisherName $pubName -Offer $offerName -Skus $skuName
.Parameter UsePlan
Some Images in the Image library require “Plan” to be a part of the deployment.
.Parameter ForcePostTasks
Enforcing Post Deployment tasks even if deployment failed. Can be useful in case of the deployment failure due to extension.
.Parameter SkipExtensions
Switch would remove any extensions (OMS / BGINFO and etc) from deployment. Should be used to skip extensions deployment. This can be useful if Deploying unsupported version of the OS, like Windows Server 2003 or Windows Server 2008
.Parameter DatadiskSizeGB
Size of the Data Disk in GB. Default is 128GB. Maximum value is 1023 GB.
.Parameter DatadisksCount
Count of the disks to be attached.
.Parameter StorageAccountID
ID (two numbers) of the storage account that will be hosting data disks.
.Parameter AttachDataVHDs
Use this switch to attache the exiting DATA VHDs for the VM you are creating from the VHD. Please not that only available when creating VM from the Existing VHD. For additional help please see "Get-Help Add-mrvExistingDataDisks -Detailed"
.Parameter EnableAcceleratedNetworking
Enables Accelerated Networking
.Parameter AlwaysOn
Sets the tag 'AlwaysOn' to True so that the VM stays up after deployment
.Parameter imageReferenceID
Reference to Azure Object ID that is representing image. Example: "/subscriptions/5d3731a5-a803-4fa6-ba02-52904c958ad3/resourceGroups/mrvP-RG-TMPL-01/providers/Microsoft.Compute/images/mrvP-WV-ICAMCLN-Image" See below : https://docs.microsoft.com/en-us/azure/virtual-network/virtual-network-create-vm-accelerated-networking#configure-wind https://azure.microsoft.com/en-us/updates/accelerated-networking-in-preview/ for supported regions
Examples
.Example
Create VM from the Azure Market Image New-MRVAzureVM -VMname "MRV-SH-TEST-015" -ResourceGroupName "MRV-RG-TEST-010" -VMIPaddress "172.20.65.15" -SubscriptionName "MSDN_01" -VMSize "Standard_D1_v2" -ChangeControl CHG0000000 -Description "TEST"
.Example
-Override can be used if we already have Interface provisioned or VM has non-standard name New-MRVAzureVM -VMname MRV-SV-XXX-004 -ResourceGroupName "MRV-RG-XXX-001" -VMIPaddress "172.20.71.XX" -SubscriptionName "MSDN_01" -VMSize "Standard_D2_v2" -Override -ChangeControl CHG0000000 -Description "TEST"
.Example
-UseExistingDisk Can be used to provisionn the VM from the existing VHD New-MRVAzureVM -VMname "MRV-SH-TEST-015" -ResourceGroupName "MRV-RG-TEST-010" -VMIPaddress "172.20.65.15" -UseExistingDisk -VMtype "MSDN_01" -VMSize "Standard_D1_v2" -ChangeControl CHG0000000 -Description "TEST"
.Example
Non standard VMs New-MRVAzureVM -VMname "MRV-SH-HI-001" -ResourceGroupName "MRV-RG-HI-001" -VMIPaddress "172.20.158.22" -SubscriptionName "MSDN_01" -VMSize "Standard_D1_v2" -imageOffer "hanu-insight" -imagePublisher "hanu" -ImageSku "standard-byol" -useplan New-MRVAzureVM -VMname "MRV-SH-XXX-001" -ResourceGroupName "MRV-RG-XXX-001" -VMIPaddress "172.20.154.XX" -SubscriptionName "MSDN_01" -VMSize "Standard_D2_v2" -ChangeControl CHG0000XXX -Description "XXXXXXXXX" -ImageSKU 8 -imagePublisher credativ -imageOffer Debian New-MRVAzureVM -VMname "MRV-SH-XXX-002" -ResourceGroupName "MRV-RG-XXX-001" -VMIPaddress "172.20.154.XX" -SubscriptionName MSDN_01 -VMSize Standard_D2_v2 -ChangeControl CHG0000XXX -Description "Microsites Windows Server" -ImageSKU '2016-Datacenter' -Imageoffer 'WindowsServer' -ImagePublisher 'MicrosoftWindowsServer'
.Example
Attach Existing Data Disks (VHDs) for the VM when creating from existing VHD. New-MRVAzureVM -VMname "MRV-SH-TEST-011" -ResourceGroupName "MRV-RG-TEST-010" -VMIPaddress "172.20.65.11" -SubscriptionName "MSDN_01" -VMSize "Standard_D2_v2" -ChangeControl CHG0000000 -Description "TEST" -UseExistingDisk -AttachDataVHDs