Hi @Billy Van Wyk (PEC) ,
Welcome to Microsoft Q&A Forum, thank you for posting your query here!
Let me provide you two solutions here
Solution 1: If we have limited number of VM where you just go the VM and perform this
Solution 2: Let us say if you have 100's of VM's solution 2 will make use using a script
Please choose above two solutions depending up on your requirement
Solution1 : Directly go the VM Blade go to tasks.
Add two tasks on is for Stop VM and one is for Start VMClick on Sign in provide your credentials
Later you can see it is connected
Schedule your stop and start activity depends up on your requirement
Solution 2:
Create an Automation account
Refer: https://learn.microsoft.com/en-us/azure/automation/quickstarts/create-azure-automation-account-portal
Create a runbook
Refer: https://learn.microsoft.com/en-us/azure/automation/learn/automation-tutorial-runbook-textual
Later enable managed identity to keep on
Refer: https://learn.microsoft.com/en-us/azure/automation/learn/automation-tutorial-runbook-textual
Follow the below screenshots
Add role assignment
Add role Assignment and provide Contributor access to the automation account or manage identity
Below script will stop the VM
Below script will Start the VM
Code Added below: -
#Connect to Azure with system-assigned managed identity
$AzureContext = (Connect-AzAccount -Identity).context
# set and store context
$AzureContext = Set-AzContext -SubscriptionName $AzureContext.Subscription -DefaultProfile $AzureContext
$vmlist = @("testtest", "myVm")
foreach ($vm in $vmlist) {
$rgname= get-azvm | where {$_.name -eq "$vm"}
Write-Host $rgname.ResourceGroupName
Stop-AzVM -Name $vm -ResourceGroupName $rgname.ResourceGroupName -Force
}
#Connect to Azure with system-assigned managed identity
$AzureContext = (Connect-AzAccount -Identity).context
# set and store context
$AzureContext = Set-AzContext -SubscriptionName $AzureContext.Subscription -DefaultProfile $AzureContext
$vmlist = @("testtest", "myVm")
foreach ($vm in $vmlist) {
$rgname= get-azvm | where {$_.name -eq "$vm"}
Write-Host $rgname.ResourceGroupName
Start-AzVM -Name $vm -ResourceGroupName $rgname.ResourceGroupName
}
let us know if you have any further queries. I’m happy to assist you further.
Please provide your valuable comments
Please do not forget to "Accept the answer” wherever the information provided helps you, this can be beneficial to other community members.