The VM info:
How to shutdown (or Stop) and de-allocate the VM in Azure without having to go to the azure portal?
Bearing in mind in Azure if you execute shutdown -h 0
; it will stop the VM but won't deallocate it.
I'm asking this because I don't have a direct connection to the Azure portal nor do I have logins to it. I want to deallocate the VM using the guest OS only.
I understand what's your scenario. You can SSH to the VM only, but cannot access the Azure. For Example you don't know the credential of Azure account.
For this scenario, you cannot deallocate the Azure VM. Because that action must need been done with Azure Account and it is completed in Azure, not just VM. Deallocate the Azure VM also links to other resources, such as Public IP address, Disk, Network interface and etc.
If you still want to deallocate the Azure VM, I suggest you call your owner of this Azure VM who can access azure portal.
Another hack around this problem is to use Azure CLI to login within the guest VM then control the VM. You will still need to login to Azure, but this is required only once.
Generate a an authentication code using the command:
az login
This will generate an authentication code that can be used to log you in via the Azure owner (only required once). Use that code to authenticate.
After login in you can issue this command to stop and deallocate your VM:
az vm deallocate --resource-group myResourceGroup --name myVM
list of available azure CLI commands can be found here