Unable to Add new User For AZURE Windows VM Using VMAccessAgent

216 Views Asked by At

I am trying to add a new username and password after creating a Windows virtual machine from the existing snapshot. I am using the java SDK sample code available on Github but this code snippet only updates the existing user's password instead of creating a new user.

Here is my code snippet

virtualMachine.update().defineNewExtension("VMAccessAgent")
.withPublisher("Microsoft.Compute")
.withType("VMAccessAgent")
.withVersion("2.3")
.withProtectedSetting("username", user)
.withProtectedSetting("password", plainTextPassword)
.attach().apply();
1

There are 1 best solutions below

1
On BEST ANSWER

i tried multiple ways and finally found the solution seems like it is case sensitive instead of withProtectedSetting use withPublicSetting for username and the change the key to UserName and Password and change the version to 2.4

    virtualMachine.update().defineNewExtension("VMAccessAgent")
        .withPublisher("Microsoft.Compute")
        .withType("VMAccessAgent")
        .withVersion("2.4")
        .withPublicSetting("UserName", user)
        .withProtectedSetting("Password", palinTextPassword)
        .attach().apply();