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,266 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: Most helpful
  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. 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