Creating VM in powershell using extension

Salves 501 Reputation points
2020-09-07T07:16:13.123+00:00

Hi,

I need to create a VM and I want to use the extensions to install IIS.

https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/tutorial-vm-extension/installWebServer.ps1 "

Can I use it in my script below?


$ NIC = New-AzNetworkInterface -Name "NetworkInterface1" -ResourceGroupName $ ResourceGroupName -Location $ LocationName -SubnetId $ Vnet.Subnets [0] .Id
$ VirtualMachine = New-AzVMConfig -VMName $ computerNames -VMSize $ VMSize
$ VirtualMachine = Set-AzVMOperatingSystem -VM $ VirtualMachine -Windows -ComputerName $ ComputerNames -Credential $ Credential -ProvisionVMAgent -EnableAutoUpdate
$ VirtualMachine = Add-AzVMNetworkInterface -VM $ VirtualMachine -Id $ NIC.Id
$ VirtualMachine = Set-AzVMSourceImage -VM $ VirtualMachine -PublisherName $ publisherName -Offer $ offer -Skus $ skus -Version latest

New-AzVM -ResourceGroupName $ ResourceGroupName -Location $ LocationName -VM $ VirtualMachine -Verbose


Thank you.

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
7,793 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Vinicius Deschamps 201 Reputation points
    2020-09-24T16:24:28.087+00:00

    Hi @Salves ,

    I believe you are looking for Desired State Configuration by having your Virtual Machine provisioned + install IIS in a single shot.

    I'd recommend to have a look at the Introduction to the Azure Desired State Configuration extension handler to get started.

    If you still have questions, don't hesitate in reach us here.

    Thanks,
    Vinicius Deschamps
    https://viniciusdeschamps.com.br

    0 comments No comments

  2. Andreas Baumgarten 108K Reputation points MVP
    2020-09-24T17:27:56.717+00:00

    Maybe this is helpful:

    Create an IIS VM with PowerShell

    Regards
    Andreas Baumgarten

    (Please don't forget to Accept as answer if the reply is helpful)

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.