Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automating wsl --update on Azure hosted Win11 VM doesn't work #8645

Closed
1 of 2 tasks
bretboss opened this issue Jul 22, 2022 · 1 comment
Closed
1 of 2 tasks

Automating wsl --update on Azure hosted Win11 VM doesn't work #8645

bretboss opened this issue Jul 22, 2022 · 1 comment

Comments

@bretboss
Copy link

bretboss commented Jul 22, 2022

Version

Microsoft Windows [Version 10.0.22000.795]

WSL Version

  • WSL 2
  • WSL 1

Kernel Version

No response

Distro Version

No response

Other Software

PowerShell Az.Compute module v4.29.0

  • Invoke-AzVMRunCommand

Repro Steps

If I try and update WSL using the System account then Access is Denied:

$result = Invoke-AzVMRunCommand -CommandId "RunPowerShellScript" -ResourceGroupName $rgName -VMName $vmName -ScriptString "wsl --update";
$result.Message;

Result

A c c e s s   i s   d e n i e d .

If I try to update WSL using an administrator account then elevation is required:

$script = @"
param(`$user,`$pwd)

`$fullUserName = "`$(`$Env:ComputerName)\`$user";
`$password = ConvertTo-SecureString -AsPlainText -String `$pwd -Force
`$credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList `$fullUserName,`$password -ErrorAction Stop;
`$session = New-PSSession -Credential `$credential -Authentication Credssp -ErrorAction Stop;
try{
    Invoke-Command -session `$session -Script {wsl --update;} -ErrorAction Stop;
} finally {
    `$session | Remove-PSSession;
}

"@

$result = Invoke-AzVMRunCommand -CommandId "RunPowerShellScript" -ResourceGroupName $rgName -VMName $vmName -ScriptString $script -Parameter @{ user=$userName; pwd=$userPwd; };
$result.Message

Result

C h e c k i n g   f o r   u p d a t e s . . .


 D o w n l o a d i n g   u p d a t e s . . .


 T h e   r e q u e s t e d   o p e r a t i o n   r e q u i r e s   e l e v a t i o n .

Expected Behavior

I was expecting to be able to update WSL using automation. We use automation on Azure VMs to create images we use elsewhere in our organization. We use Docker Desktop in this image which requires us to update WSL to its latest version.

Actual Behavior

I have not found a way to elevate the user for wsl --update. All other commands that require user elevation succeed. Example:

Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux -All -NoRestart

So I think the The requested operation requires elevation message is incorrect.
But I may be missing something.

Diagnostic Logs

No response

@bretboss bretboss changed the title Automating wsl --update on Azure hosted VM doesn't work Automating wsl --update on Azure hosted Win11 VM doesn't work Jul 22, 2022
Copy link
Contributor

This issue has been automatically closed since it has not had any activity for the past year. If you're still experiencing this issue please re-file this as a new issue or feature request.

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant