Start and Stop Azure Virtual Machine - azure

I need to start / stop a Azure virtual machine, but I don't know how I can do this. I don't know anything about Azure or Azure scripts.

You have several options.
The first one is by using the Azure Portal. Click on your VM and at the bottom you should see a button to stop the virtual machine. Starting it again works the same way.
The second option is to use PowerShell. John McCabe has posted a simple script on his blog to do this. The most important functions are Start-AzureVM and Stop-AzureVM.
If you want to automate this from a developer perspective (which needs a little bit more work than the PowerShell solution) is by using the Azure Management Libraries. Brady Gaster wrote a great post about it.
The fourth option is to use Microsoft Azure Automation. There you create runbooks for common tasks. In the samples are scripts already included which can start and stop a VM.

You can also create a Timer-triggered Azure Function to start/stop your VM. I've provided the steps here:
Azure Function role like permissions to Stop Azure Virtual Machines
Instead of creating HTTP-triggered Functions, just use Timer-triggered functions instead and edit the PowerShell script content to hardcode the vmname and resourcegroup.

within the Azure portal (I would recommend using the new portal), go into the VM you need, on the dashboard you will see a Stop and Start button, or you can choose to Restart the VM. Hope this helps.

Related

How to start azure VM automatically without automation account

We have a Virtual Machine which scheduled to stop automatically on every end of the day.
Next day when we want to connect to it, we need to explicitly login to Azure portal, select Virtual machine and click on start.
I know we can schedule it using automation account (due to some restrictions in office environment cant use automation account) but is there any way we can achieve this?
Thinking of any way of -
Creating a batch file on my local machine which just start the VM
when I run it without logging into Azure portal?
Any other simple setting like we have to schedule auto stop?
Any other hint will be a great help.
Thank you!
you can just use az cli and\or powershell and script the vm to start, its extremely straight forward (something like az vm start -g rg_name -n vm_name).
There are no built-in startup solutions yet.

How to disable Azure Portal environment

Is it possible to Inactivate Azure Portal particular environment. Like, only development environment and whenever need then, re-activate again ?
Reason is like, its not going to use for next couple of month so, would like to make it disable.
You should look at DevTest Labs which you could configure and use it whenever you want.
Fast, easy, and lean dev-test environments in Azure.Specifically for your team which can be run On demand.
EDIT:
Simple answer is NO. However when you are using ARM templates to create the resources and do the deployment those resources will be created again. Usually Azure Paas is more about Pay as you go.I do not see a requirement to disable those and activate again.

Delete an Azure Virtual Machine automatically after deployment

To deploy my infrastructure I need to deploy a VM with a custom script extension. The only purpose of the VM, is to execute the script. After the execution of the script the VM should be deleted automatically.
How can this be done?
Additional information:
This is an azure resource manager deployment
the deletion should work in the azure marketplace environment as well.
this probably means you are doing something wrong, you can use Azure Container Instance to run the script and shutdown. it should work with marketplace as well (as far as I know you can have custom container in marketplace offerings).
Marketplace only allows you to use arm templates to deploy stuff, so you cannot really do what you are asking with an arm template. well, you might be able to hack something like that with nested deployments and complete mode, but I doubt that will pass moderation in marketplace.
technically, you can make vm delete itself as a part of the script. again, not something I would advise.

Add a PowerShell script to Azure Marketplace Offer

I would like to publish an Azure Managed Application to the Azure Marketplace. Is it possible to add to the "app.zip" an own PowerShell Script, which executes some additional deployment steps besides the Azure Resource Manager Template?
The Script would invoke the arm template and handle some outputs of the Template
The way to think about these is that you can only do tasks that can be done in a template. Today, there's no way to run an arbitrary script in an ARM template.
That help?
After some research and contacting the MS Support I found two possible solutions:
Using a VM with a Custom Script Extension. Downside: VM needs long to startup and is expensive if we do not delete it afterwards.
Using a Azure Container Instance to run the script. Starts up in about 45 seconds and doesn't cost anything if we don't use it. -> Tutorial

Run a script on VM before it's deleted in Azure

Is there a way to run bash script on a VM before it's deleted from Azure? I know you can use CustomScriptExtension for running script when VM is created or started but I couldn't find any information about launching cleanup scripts before VM is deleted.
No, at the time of writing Azure does not support actions like this.
Depending on what you want to do, you may find it useful to subscribe to VM alerts, which can include when it is deleted. You'll have the option to call a webhook that may give you the flexibility to do what you need. Try working within the Azure portal Monitoring Blade to create your own Alert to handle this.

Resources