This article has not been completed yet. However, it may already contain   helpful Information and therefore it has been published at this stage.

First create an Azure Automation account in the region of your choice.

Now that we have our Azure Automation account, its time to set up the System Managed Identity and grant it the following roles:

  • Virtual Machine Contributor (to deallocate the Virtual Machine)

After the successful creation and configuration of the automation account, go to the specific VM that the user will use and add a tag. For example, specify whether you want to control the VM externally.

Now create the scripts for the VM start and the VM stop actions.

Start VM:

try
{
    "Logging in to Azure..."
    Connect-AzAccount -Identity
}
catch {
    Write-Error -Message $_.Exception
    throw $_.Exception
}

$TagName = "Remote Control"
$TagValue = "true"

$VMs = Get-AzResource -TagName $TagName -TagValue $TagValue | Where-Object -FilterScript {$_.ResourceType -like 'Microsoft.Compute/virtualMachines'}
$VMs

foreach ($VM in $VMs) {
Start-AzVM -ResourceGroupName $VM.ResourceGroupName -Name $VM.Name -Verbose
}

Stop VM:

try
{
    "Logging in to Azure..."
    Connect-AzAccount -Identity
}
catch {
    Write-Error -Message $_.Exception
    throw $_.Exception
}

$TagName = "Remote Control"
$TagValue = "true"

$VMs = Get-AzResource -TagName $TagName -TagValue $TagValue | Where-Object -FilterScript {$_.ResourceType -like 'Microsoft.Compute/virtualMachines'}

foreach ($VM in $VMs) {
Stop-AzVM -ResourceGroupName $VM.ResourceGroupName -Name $VM.Name -Force -Verbose
}

Next step is to upload the scripts into the Automation account to create the runbooks.

Set an appropriate expiration date and make sure you have copied the webhook URL. You will not have access to the URL after you hit OK.

Follow the same procedure for the Stop VM script.

Finally, you can create the PowerShell scripts (one to start and one to stop the VM) for the user to call the webhooks with them.

Invoke-WebRequest -Method Post -Uri <webhookurl>

References:

Start and stop Azure VMs without access to Microsoft Azure

Turn on a Azure Virtual Machine using Azure Automation
Turning off a Virtual Machine in Microsoft Azure on a schedule can quickly be done using the built-in Shutdown controls in the Virtual Machine blade (part of Azure Lab Services, but not a requirement), but what about starting it?
Retirement notice: Transition Azure Automation Run As accounts to Managed identities by 30 September 2023 - Microsoft Q&A
Microsoft Q&A is the best place to get answers to all your technical questions on Microsoft products and services. Community. Forum.