Azure VM: reset local user account password

Arif Usman 421 Reputation points
2022-08-19T03:20:06.357+00:00

folks, I have about 200 az vm, contains local user account. I need to reset password for all vms. Now I can do it through portal fine, but like to do scripting.

I tried with
$Computer = "TestVM"
$vmcomp = Get-AzVM -Name $Computer
$vmName = $vmcomp.Name
$resourceGroupName = $vmName.ResourceGroupName
$location = $vmName.Location
$Password = "*P@ssword2022!!"
$UserName = "AzureVM"

        Set-AzureRmVMAccessExtension -ResourceGroupName $resourceGroupName -VMName $vmName -Name $name -Location $location -typeHandlerVersion "2.0" -ForceRerun  

but didn't work, can someone give me examples or any ideas here

Thanks In Advance......

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
7,267 questions
0 comments No comments
{count} votes

Accepted answer
  1. Andreas Baumgarten 98,621 Reputation points MVP
    2022-08-21T07:40:30.653+00:00

    Hi @Arif Usman ,

    The Az is the newer module and the replacement for the older AzureRM module.
    I would recommend to use the Az only.
    https://learn.microsoft.com/en-us/powershell/azure/new-azureps-module-az?view=azps-8.2.0

    To uninstall the AzureRM module you could try the Uninstall-AzureRM cmdlet (which is in the Az.Account module): https://learn.microsoft.com/en-us/powershell/module/az.accounts/uninstall-azurerm?view=azps-8.2.0

    Some more useful information you will find here:
    https://basvo.github.io/azure/azurerm/powershell/2021/03/05/remove-azurerm-before-installing-az-module.html
    https://stackoverflow.com/questions/34204373/how-to-clean-up-bad-azure-powershell-uninstall

    ----------

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards
    Andreas Baumgarten

    0 comments No comments

10 additional answers

Sort by: Newest
  1. Andreas Baumgarten 98,621 Reputation points MVP
    2022-08-21T15:39:58.023+00:00

    Hi @Arif Usman ,

    please try the Set-AzVMAccessExtension without the -TypeHandlerVersion parameter:

    Set-AzVMAccessExtension -Credential $cred -Location "$location" -Name "PasswordReset" -ResourceGroupName "$resourceGroupName" -VMName "$vmName"  
    

    Before running the script/command please verify if an extension from type Microsoft.Compute.VMAccessAgent is already installed on the VM. If so please delete the extension.
    This can be done in the Azure Portal or via PowerShell:

    $ext = Get-AzVMExtension -VMName $vmName -ResourceGroupName $resourceGroupName | Where-Object { $_.ExtensionType -eq "VMAccessAgent" }  
    if ($ext) {  
        Remove-AzVMAccessExtension -VMName "$vmName" -ResourceGroupName "$resourceGroupName" -Name "$($ext.Name)" -Force  
    }  
    

    You can check the available versions of the extension by running the following command (just change the -Location parameter to the region your VM is running):

    Get-AzVMExtensionImageType -PublisherName "Microsoft.Compute" -Location "northeurope" | Get-AzVMExtensionImage | Select Type, Version, PublisherName  
    

    ----------

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards
    Andreas Baumgarten

    0 comments No comments

  2. Arif Usman 421 Reputation points
    2022-08-21T14:53:52.71+00:00

    still getting conflict message.
    233262-image.png

    0 comments No comments

  3. Andreas Baumgarten 98,621 Reputation points MVP
    2022-08-22T06:51:17.5+00:00

    Hi @Arif Usman ,

    this is really weird.

    I am running the Az module version 8.2

    Get-InstalledModule Az  
    

    I am logged in to Azure with an account that is Owner of the subscription.
    My vm is running in the Azure region "NorthEurope".

    Before:

    233310-image.png

    I am running this script without any error message:

    $UserName = "AzureVM"  
    $Password = "*P@ssword2022!!"  
    $Computer = "Repair01"  
    $secPassword = ConvertTo-SecureString $Password -AsPlainText -Force  
    $cred = New-Object System.Management.Automation.PSCredential ($userName, $secPassword)  
    $vmcomp = Get-AzVM -Name $Computer  
    $vmName = $vmcomp.Name  
    $resourceGroupName = $vmcomp.ResourceGroupName  
    $location = $vmcomp.Location  
    Set-AzVMAccessExtension -Credential $cred -Location "$location" -Name "PasswordReset" -ResourceGroupName "$resourceGroupName" -VMName "$vmName"   
    

    And the result will look like this:

    233366-image.png

    In which Azure region is your vm running?

    There was an reported issue some time ago (October 2021):
    https://learn.microsoft.com/en-us/answers/questions/588466/no-version-found-in-the-artifact-repository-that-s.html
    Based on the thread it should have been resolved.

    It might be an option to create a support request with Microsoft to get your issue resolved.
    https://learn.microsoft.com/en-us/azure/azure-portal/supportability/how-to-create-azure-support-request

    Or you could try the second option I posted before. There is no Set-AzVMAccessExtension involved but should be the same result -> Password of user should be modified.
    https://github.com/abaumgarten42/Azure_Stuff/tree/main/Azure_VMs/RunPowerShellScriptsOnVMs

    ----------

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards
    Andreas Baumgarten

    1 person found this answer helpful.
    0 comments No comments

  4. ausman_sa 1 Reputation point
    2022-08-22T03:04:12.343+00:00

    @Andreas Baumgarten : I really appreciate all help getting from you.

    So I follow your direction and it did removed vmaccessgent (2nd script).
    then i ran the last script to get-azvmextensionimage and found this.
    233381-image.png

    but when i ran Set-AzVMAccessExtension i am getting following.
    233315-image.png

    0 comments No comments