Skip to content

Instantly share code, notes, and snippets.

@jjgriff93
Last active February 4, 2018 01:38
Show Gist options
  • Select an option

  • Save jjgriff93/8e948234d94197c21556e6eac3646ca0 to your computer and use it in GitHub Desktop.

Select an option

Save jjgriff93/8e948234d94197c21556e6eac3646ca0 to your computer and use it in GitHub Desktop.
Azure .NET mgmt API - program.cs to create VM
using System;
using Microsoft.Azure.Management.Compute.Fluent;
using Microsoft.Azure.Management.Compute.Fluent.Models;
using Microsoft.Azure.Management.Fluent;
namespace FluentAPIApp
{
class Program
{
static void Main(string[] args)
{
var azure = Azure.Authenticate("Azure-authentication.txt").WithDefaultSubscription();
Console.WriteLine("Creating a new VM...");
var windowsVM = azure.VirtualMachines.Define("VMCreatedWithFluent")
.WithRegion("West Europe")
.WithNewResourceGroup("FluentRG")
.WithNewPrimaryNetwork("10.0.0.0/28")
.WithPrimaryPrivateIPAddressDynamic()
.WithNewPrimaryPublicIPAddress("fluentdns")
.WithPopularWindowsImage(KnownWindowsVirtualMachineImage.WindowsServer2012Datacenter)
.WithAdminUsername("serverAdmin")
.WithAdminPassword("mySuperSecurePassword18")
.WithSize(VirtualMachineSizeTypes.StandardDS3V2)
.Create();
Console.WriteLine("Successfully created a new VM: {0}!", windowsVM.Id);
Console.WriteLine("Press any key to exit...");
Console.ReadLine();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment