Hi. Thank you for your question and reaching out. I’d be more than happy to help you with your query.
Here is a sample script to create a Windows Server 2016 Datacenter virtual machine in Azure using PowerShell:
Import the AzureRM module
Import-Module AzureRM
Connect to Azure
Connect-AzureRmAccount
Select the Azure subscription you want to use
Select-AzureRmSubscription -SubscriptionId "your-subscription-id"
Set the resource group name
$resourceGroupName = "your-resource-group-name"
Create a new resource group
New-AzureRmResourceGroup -Name $resourceGroupName -Location "West US"
Set the virtual machine name
$vmName = "your-virtual-machine-name"
Set the admin username and password
$adminUsername = "your-admin-username"
$adminPassword = "your-admin-password" | ConvertTo-SecureString -AsPlainText -Force
Create a new virtual machine configuration
$vmConfig = New-AzureRmVMConfig -VMName $vmName -VMSize "Standard_DS1_v2"
$vm = Add-AzureRmVMOSDisk -VM $vmConfig -Name $vmName -Windows -CreateOption FromImage -StorageAccountType Standard_LRS -DiskSizeInGB 128 -ImageName "Win2016Datacenter"
$vm = Set-AzureRmVMOperatingSystem -VM $vm -Windows -ComputerName $vmName -Credential (New-Object PSCredential -ArgumentList $adminUsername, $adminPassword)
$vm = Add-AzureRmVMNetworkInterface -VM $vm -Name "your-network-interface-name" -ResourceGroupName $resourceGroupName
Create the virtual machine
New-AzureRmVM -ResourceGroupName $resourceGroupName -Location "West US" -VM $vm
Note: Replace your-subscription-id, your-resource-group-name, your-virtual-machine-name, your-admin-username, and your-admin-password with the appropriate values. Additionally, you may need to change the -Location and -VMSize to match your desired configuration.
If the reply was helpful, please don’t forget to upvote or accept as answer, thank you.