azure vm password reset using python

Vaishnav AV-FT 81 Reputation points
2024-05-13T08:50:45.4966667+00:00

I am trying to reset azure vm (both windows and linux) password using python as part of automation.Does azure.mgmt.compute module support VM password rotation. If so please help me with a basic snippet.

when ever I try to do :

compute_client.virtual_machines.begin_update(
            resource_group_name,
            vm_name,
            {
                'osProfile': {
                    'adminPassword': new_password
                }
            }
        ).wait()

Password is getting reset but am not able to login with old or new password

Not Monitored
Not Monitored
Tag not monitored by Microsoft.
36,404 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Vaishnav AV-FT 81 Reputation points
    2024-05-16T12:41:13.2733333+00:00

    Got a solution from MS:

    https://github.com/Azure/azure-sdk-for-python/issues/35598

    For linux:

    from azure.mgmt.compute.models import VirtualMachineExtension
    response = client.virtual_machine_extensions.begin_create_or_update(
        resource_group_name={resource_group_name}, 
        vm_name={vm_name}, 
        vm_extension_name='enablevmaccess', 
        extension_parameters=VirtualMachineExtension(
            location={location}, 
            protected_settings={'username': {username}, 'password': {password}}))
    

    For Windows:

    response = client.virtual_machine_extensions.begin_create_or_update(
        resource_group_name={resource_group_name}, 
        vm_name={vm_name}, 
        vm_extension_name='enablevmaccess', 
        extension_parameters=VirtualMachineExtension(
            location={location}, 
            publisher='Microsoft.Compute',
            type_properties_type='VMAccessAgent', 
            type_handler_version='2.4', 
            protected_settings={'password': {password}}, 
            settings={'userName': {username}}))
    
    0 comments No comments