We manage a lot of Virtual Machines on Azure. From time to time, these VMs need to be restarted for various technical reasons. The `Microsoft.WindowsAzure.Management.Compute` namespace available on NuGet (here) allows developers to programatically control the shutdown, startup and restarts of Azure based virtual machines for a particular Azure subscription. The code samples below are slightly incomplete and will require a bit of modification to make them relevant to your needs.
/// <summary>
/// This class is both a model for Dapper and accessor for the Azure compute restart functionality.
/// </summary>
public class VirtualMachine : IVirtualMachine
{
    public int ID { get; set; }

    public string RoleName { get; set; }

    public string HostServiceName { get; set; }

    public string DeploymentName { get; set; }

    public DateTime? LastRestarted { get; set; }

    private CertificateCloudCredentials cloudCredentials = MyCredentials.GenerateCloudCredentials();

    private ComputeManagementClient managementClient;

    public VirtualMachine()
    {
        // Create a new instance of the client
        managementClient = new ComputeManagementClient(cloudCredentials);
    }

    public void Restart()
    {
        // Get the response from the request to shut down this particular VM. 
        OperationStatusResponse response = managementClient.VirtualMachines.Restart(HostServiceName, DeploymentName, RoleName);

        StringBuilder sb = new StringBuilder();

        sb.AppendLine("Virtual Machine: " + RoleName);

        if (response.Error != null)
        {
            sb.AppendLine("An error has occurred");
            sb.AppendLine("Error Message: " + response.Error.Message);
            sb.AppendLine("Error Code: " + response.Error.Code);
        }
        else
        {
            sb.AppendLine("Restart successful");
            sb.AppendLine("Status: " + response.Status);
            sb.AppendLine("StatusCode: " + response.StatusCode);

        }

        List<string> emails = new List<string>()
        {
            "[email protected]", "[email protected]"
        };

        foreach(string email in emails)
        {
            // Send some emails
        }
            
    }

    public void Stop()
    {
        throw new NotImplementedException();
    }

    public void Start()
    {
        throw new NotImplementedException();
    }
}
Where `IVirtualMachine` is a public interface exposing a couple of methods that we want to perform on any given VM:
public interface IVirtualMachine
{
    void Restart();

    void Stop();

    void Start();
}
In order to generate an instance of the `CertificateCloudCredentials` class we need to generate a `pfx` file of the Azure subscription certificate. If you've used Azure before, you will likely be able to find the Subscription certificates already installed on your local PC. The process to generate a pfx file for an Azure subscription is detailed at http://blogs.technet.com/b/orchestrator/archive/2014/04/11/managing-azure-services-with-the-microsoft-azure-automation-preview-service.aspx Finally the static `MyCredentials` class returns the `CertificateCloudCredentials` instance to the caller. Please fill in the relevant variables marked with `XXX` below with your Azure subscription ID, the name of the generated `pfx` file (I put my pfx file into a folder called "Certificates") and also the password that you chose for the pfx file:
public static class MyCredentials
{
    public static string subscriptionId = "XXX";

    public static string certificateFilePath = "XXX.pfx";

    public static string certificatePassword = "XXX";

    public static CertificateCloudCredentials GenerateCloudCredentials()
    {
        var appDomain = System.AppDomain.CurrentDomain;
        var basePath = appDomain.RelativeSearchPath ?? appDomain.BaseDirectory;
            
        X509Certificate2 cert = new X509Certificate2(Path.Combine(basePath, "Certificates", certificateFilePath), certificatePassword);

        CertificateCloudCredentials creds = new CertificateCloudCredentials(subscriptionId, cert);

        return creds;
    }
}
And that is it! You should be able to restart your VMs. I set up a WebJob inside of an Azure website to run this on a continuous basis.