Skip to main content

Stop Azure Virtual Machine

As Azure user I can be STOP the running VM. When you stop it. All services related to that will be get stopped. So before stopping VM make sure you have some reason behind on it. 

Azure Virtual Machine can be stopped two ways.

  • Manually Stop VM
  • API request to Stop VM

1.Manually Stop VM : Go To VM overview page - click STOP button - Click OK



2.API request to Stop VM

Build API request and Stop Azure Virtual Machine.

Collect Arguments information

 {0} - subscriptionId {1} - resourceGroupName {2} -  virtualMachinesName {3} - apiVersion

Variables 

private string azureDomain = "https://management.azure.com";
private string vmStopUri = "/subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.Compute/virtualMachines/{2}/powerOff?api-version={3}";
private string _apiV_2019_12_01 = "2019-12-01";

 Write a Method

  public void StopVirtualMachine(string vmName)
        {
            string vmStopUrl = string.Format(azureDomain + vmStopUri, _subscriptionId, _resourceGroupName, vmName, _apiV_2019_12_01);
            _apiRequest.PostRESTfulResponseWithToken(_token, vmStopUrl, "");
            Thread.Sleep(30000);
        }
 
 Once VM has been stopped. You can try to access, Finally you will get below warning.
 

Comments

Popular posts from this blog

CREATE AZURE VIRTUAL MACHINE

As a Azure user I can create VM machine within 3 min by following below said ways.  1.Manually create VM via Wizard 2.API request to create VM   1.Manually create VM via Wizard - Go to VM wizard and fill VM details VM successfully created. 2.API request to create VM string ip_St = "Ip"; string vNet_St = "VNet"; string sub_St = "Subnet"; string nic_St = "Nic"; string nsg_St = "nsg"; //Setp1 CreatePulicIpAddress(ip_St); //Setp2 CreateVirtualNetworks(vNet_St); //Setp3 CreateSubnets(vNet_St, sub_St); //Setp4 CreateNetworkSecurityGroups(nsg_St); //Step5 CreateNetworkInterfaces(nic_St, ip_St, vNet_St, sub_St, nsg_St); //Setp6 CreateVirtualMachine(vmDetails); private string azureDomain = "https://management.azure.com"; private string apiVersion = "2019-12-01"; private string _apiV_2019_12_01 = "2019-12-01"; private strin...

MICROSOFT.NETWORK API COLLECTIONS

Recently I used Microsoft network rest API call. I would like to share with you all. Network API calls includes  PublicIpAddress, VirtualNetworks, Subnets, NetworkInterfaces, Disks, NetworkSecurityGroups.  GET, PUT, DELETE -  Mostly I used {0} - subscriptionId  {1} - resourceGroupName  {2} - virtualMachinesName{3} - apiVersion  private string azureDomain = "https://management.azure.com"; private string apiVersion = "2019-12-01"; private string _apiV_2019_12_01 = "2019-12-01"; private string _apiV_2019_07_01 = "2019-07-01"; private string _apiV_2020_04_01 = "2020-04-01"; private string publicIpAddressPutUri = "/subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.Network/publicIPAddresses/{2}?api-version={3}"; private string publicIpAddressDeleteUri = "/subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.Network/publicIPAddresses/{2}?api-version={3}"; private string...