Using PowerShell to Generate Azure VMs
-
Good morning!
Microsoft has some excellent documentation on using PowerShell to create virtual machines in Azure. It even tells you how to clean everything up at the end, so you're not charged.
https://docs.microsoft.com/en-us/powershell/azure/azureps-vm-tutorial?view=azps-8.2.0
I have several questions about specific settings for the VM:
-
What PS settings do I use to create a Standard HDD with a specific size that is NOT cached?
-
After the VM is created, it's automatically provisioned and starts to run. Is there a way to tell Azure NOT to boot up the VM automatically?
-
-
@Bedrock1977 , I hope all is well.
Creating a disk with a specific size that is not cached is pretty straightforward; you would want to use the
New-AzVMDataDisk
cmdlet and the -caching parameter, which can be set to one of three values: None, ReadOnly, ReadWriteRead about it here:
https://docs.microsoft.com/en-us/powershell/module/az.compute/new-azvmdatadisk?view=azps-8.2.0
There is no great way to prevent the VM from starting up once it is being created via PowerShell or the Azure CLI in Azure to be honest.
What you could do is to add the Stop-AzVM cmdlet to the end of the PowerShell script to turn off the VM after it is deployed.
You can read more about it here:
https://docs.microsoft.com/en-us/powershell/module/az.compute/stop-azvm?view=azps-8.2.0
You could use Azure Automation & several other approaches including Auto Shutdown to achieve something similar, but it can be much more involved. Again, you can read about the different approaches here if interested:
I hope that helps... Keep up the great questions !!!
Good Luck !!!
Cheers,
Adam