Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

168
Vistas
syntax to resize an Azure virtual machine programatically

Using C#, how do I resize an Azure virtual machine that is already stopped? The Microsoft documentation is non-existent or impossible to discover. In my .Net Standard 2.0 class library I am referencing the Nuget package Microsoft.Azure.Management.Fluent 1.37.1 and have tried the code below.

using Microsoft.Azure.Management.Fluent;
using Microsoft.Azure.Management.ResourceManager.Fluent;
using Microsoft.Azure.Management.ResourceManager.Fluent.Authentication;
...

// get Azure client
string clientId = ...;
string clientSecret = ...;
string subscriptionId = ...;
string tenantId = ...;
AzureEnvironment env = ...;
AzureCredentials creds = new AzureCredentialsFactory().FromServicePrincipal(clientId, clientSecret, tenantId, env);
IAzure azure = Microsoft.Azure.Management.Fluent.Azure
                   .Configure()
                   .WithLogLevel(HttpLoggingDelegatingHandler.Level.BodyAndHeaders)
                   .Authenticate(creds)
                   .WithSubscription(subscriptionId);

// get virtual machine
string resourceGroupName = "MyResourceGroup";
string machineName = "MyHostname";
IVirtualMachine vm = await azure.VirtualMachines.GetByResourceGroupAsync(resourceGroupName, machineName)

// resize virtual machine
VirtualMachineSizeTypes size = ...;
vm.Inner.HardwareProfile.VmSize = size;
vm.Inner.Validate();
vm.Update();  // nothing happens, virtual machine does not resize

On the last line, vm.Update() does nothing. In the Azure portal I can see that the virtual machine has not resized even after refreshing the portal multiple times.

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

The Azure API discoverability is terrible. I finally got resize working. Replace the last 3 lines

vm.Inner.HardwareProfile.VmSize = size;
vm.Inner.Validate();
vm.Update();

with

VirtualMachineUpdate parameters = new VirtualMachineUpdate()
{
    HardwareProfile = new HardwareProfile(size),
};
VirtualMachineInner response = await azure.VirtualMachines.Inner.UpdateAsync(resourceGroupName, vm.Name, parameters);
over 4 years ago · Santiago Trujillo Denunciar

0

You had it almost right. Update() is a fluent operator:

var size = VirtualMachineSizeTypes.StandardB2s;
await vm.Update()
 .WithSize(size)
 .ApplyAsync();
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda