Tuesday, December 15, 2015

Reset admin VM password on Azure (create a user when you are locked out of the vm) on ARM aka V2.

Pre-requisite: Ensure that the VM is running.
Reset password: You need to create a different user with the same privilege as the original admin user. After you login to the box, change the original admin’s password.

Important points:
1.       Powershell doesn’t work
a.       Approach 1:
 #select vm
$centosvm =
    (Get-AzureRmVM |
     Out-GridView `
        -Title "Select an Azure VM ..." `
        -PassThru)


PS C:\Users\XXX> $centosvm | Set-AzureRmVMOperatingSystem -Credential $cred -Linux -ComputerName $centosvm.Name| Update-AzureRmVM
Update-AzureRmVM : PropertyChangeNotAllowed: Changing property 'osProfile' is not allowed.
OperationID : '4df65df4-eda1-4b2c-88ba-2195fe4fa32d'
At line:1 char:97
+ ... redential $cred -Linux -ComputerName $centosvm.Name| Update-AzureRmVM
+                                                          ~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Update-AzureRmVM], ComputeCloudException
    + FullyQualifiedErrorId : Microsoft.WindowsAzure.Commands.Common.ComputeCloudException,Microsoft.Azure.Commands.Compute.UpdateAzureVMCommand
b.       Approach 2:
PS C:\Users\xxxx> $centosvm = Get-AzureRmVM | Where-Object {$_.name -eq "$vmname"}


PS C:\Users\xxxx> Set-AzureRmVMOperatingSystem -ComputerName centosweb1hdicp -Credential $vmAdminCreds -Linux -VM $centosvm
PS C:\Users\xxxx> $vmconfig = Set-AzureRmVMOperatingSystem -ComputerName centosweb1hdicp -Credential $vmAdminCreds -Linux -VM $centosvm

PS C:\Users\xxxx> Update-AzureRmVM -ResourceGroupName HDInsightHBTC -VM $vmconfig
Update-AzureRmVM : PropertyChangeNotAllowed: Changing property 'osProfile' is not allowed.
OperationID : 'dd785f5b-0bbc-4b0a-bf75-0bf722d4b476'
At line:1 char:1
+ Update-AzureRmVM -ResourceGroupName HDInsightHBTC -VM $vmconfig
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Update-AzureRmVM], ComputeCloudException
    + FullyQualifiedErrorId : Microsoft.WindowsAzure.Commands.Common.ComputeCloudException,Microsoft.Azure.Commands.Compute.UpdateAzureVMCommand

2.       ARM json snippet doesn’t work
        "osProfile": {
                "computerName":"centosweb1hdicp",
          "adminUsername": "MppUsWest2admin",
          "adminPassword": "Xxxx1@3$"
        },         
3.       Cli reset works
azure vm reset-access -n "vmname" -g "RGName"  -u "new user id" -p "new password"
info:    Executing command vm reset-access
info:    Looking up the VM "vmname"
info:    Installing extension "VMAccessForLinux", VM: "vmname"

info:    vm reset-access command OK 

1 comment: