Azure / repair-script-library

Organize and archive known repair scripts to enable anyone to easily fix their machines. The scripts are made primarily to repair VMs on the cloud.
MIT License
38 stars 39 forks source link

the win-create-troubleshooting-user script fails with error #66

Closed t-bates123 closed 12 months ago

t-bates123 commented 12 months ago

"message": "Script completed with errors.", "output": "[Error 11/09/2023 17:25:37]END: Script failed with error: A parameter cannot be found that matches parameter name 'Encoding'.\n20231109172537\n[Error 11/09/2023 17:25:38] A parameter cannot be found that matches parameter name 'Encoding'. at , C:\Packages\Plugins\Microsoft.CPlat.Core.RunCommandWindows\1.1.15\Downloads\repair-files-20231109172523\repair-script-library\Azure-repair-script-library-6db2d93\src\windows\win-create-troubleshooting-user.ps1: line 175\nat , : line 1\nat , C:\Packages\Plugins\Microsoft.CPlat.Core.RunCommandWindows\1.1.15\Downloads\script0.ps1: line 23", "resource_group": "repair-STGTAvayaVM-W10-20231109171703",

rjmccallumbigl commented 12 months ago

How was the cmdlet ran? I can try to repro

Was it like az vm repair run -g $rg -n $vm --run-id 'win-create-troubleshooting-user' --verbose --run-on-repair or maybe az vm repair run -g $rg -n $vm --run-id 'win-create-troubleshooting-user' --run-on-repair --parameters username='trblAcct' password='welcomeToAzure!1' --verbose?

t-bates123 commented 12 months ago

Hello,

I used the following command: az vm repair run -g -n --run-on-repair --run-id win-create-troubleshooting-user --verbose

Thank you, From: Ryan McCallum @.> Sent: Thursday, November 9, 2023 12:03 PM To: Azure/repair-script-library @.> Cc: Travell Bates @.>; Author @.> Subject: [EXTERNAL] Re: [Azure/repair-script-library] the win-create-troubleshooting-user script fails with error (Issue #66)

How was the cmdlet ran? I can try to repro Was it like az vm repair run -g $rg -n $vm --run-id 'win-create-troubleshooting-user' --verbose --run-on-repair or maybe az vm repair run -g $rg -n $vm --run-id 'win-create-troubleshooting-user' --run-on-repair

How was the cmdlet ran? I can try to repro

Was it like az vm repair run -g $rg -n $vm --run-id 'win-create-troubleshooting-user' --verbose --run-on-repair or maybe az vm repair run -g $rg -n $vm --run-id 'win-create-troubleshooting-user' --run-on-repair --parameters username='trblAcct' password='welcomeToAzure!1' --verbose?

rjmccallumbigl commented 12 months ago

It ran successfully for me on a Windows Server 2016 Datacenter repair VM:

# First I created my repair VM
az vm repair create --associate-public-ip --verbose --enable-nested --repair-username
"rymccall" --repair-password "###" -g 'workingVM' -n 'MyVM'

# I made sure a copy of 'MyVM's OS disk was attached to the rescue VM. Then I ran this command to create a troubleshooting user on it through the rescue vm:

az vm repair run -g 'workingVM' -n 'MyVM' --run-on-repair --run-id win-create-troubleshooting-user --verbose
Searching for repair-vm within subscription...
Found repair VM: /subscriptions/*****/resourceGroups/repair-MyVM-20231109185857/providers/Microsoft.Compute/virtualMachines/repair-MyVM_

Running script on repair VM: repair-MyVM_

Script returned with output:
[Output 11/09/2023 19:34:57]START: Running script win-create-troubleshooting-user
[Output 11/09/2023 19:34:59]#02 - Bringing disk online
[Output 11/09/2023 19:35:05]#03 - enumerate partitions for boot config
[Output 11/09/2023 19:35:05]#04 - updating local policy files

    Directory: F:\Windows\System32\GroupPolicy

Mode                LastWriteTime         Length Name

----                -------------         ------ ----

-a----        11/9/2023   7:35 PM              0 gpt.ini

    Directory: F:\Windows\System32\GroupPolicy\Machine\Scripts

Mode                LastWriteTime         Length Name

----                -------------         ------ ----

-a----        11/9/2023   7:35 PM              0 scripts.ini

    Directory: F:\Windows\System32\GroupPolicy\Machine\Scripts\Startup

Mode                LastWriteTime         Length Name

----                -------------         ------ ----

-a----        11/9/2023   7:35 PM              0 FixAzureVM.cmd
[Output 11/09/2023 19:35:06]END: Start the nested VM and login with the troubleshooting account:
[Output 11/09/2023 19:35:06]USERNAME: azure-recoveryID
[Output 11/09/2023 19:35:06]PASSWORD: ****************
[Output 11/09/2023 19:35:06]Remove the account and the following files after troubleshooting has been completed:
[Output 11/09/2023 19:35:06]F:\Windows\System32\GroupPolicy\gpt.ini
[Output 11/09/2023 19:35:06]F:\Windows\System32\GroupPolicy\Machine\Scripts\scripts.ini
[Output 11/09/2023 19:35:06]F:\Windows\System32\GroupPolicy\Machine\Scripts\Startup\FixAzureVM.cmd

Your error message indicates there was an issue with line 175: https://github.com/Azure/repair-script-library/blob/6db2d9331fe979f4dd3fbb63e05a252dfbd004c9/src/windows/win-create-troubleshooting-user.ps1#L175C13-L175C87

Which is strange because -Encoding is a valid parameter, at least in PowerShell 5.1: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/add-content?view=powershell-5.1

What OS are you using and what version of PowerShell? I'm thinking if it's older than 5.1 that is the reason and I totally didn't think of it lol

I will remove this param in a new PR and see if that works in your environment.