Skip to content

Instantly share code, notes, and snippets.

@gravcat
Last active February 2, 2018 15:53
Show Gist options
  • Select an option

  • Save gravcat/723d3a3461dba4a660a18ca4b1472618 to your computer and use it in GitHub Desktop.

Select an option

Save gravcat/723d3a3461dba4a660a18ca4b1472618 to your computer and use it in GitHub Desktop.
workaround to install and initiate the Windows Subsystem for Linux via Task Scheduler
if (!(Test-Path "C:\_maintainer")) {
New-Item -Type Directory "C:\_maintainer"
}
Invoke-WebRequest -Uri "https://gist.githubusercontent.com/gravcat/4ceb977916c5f551cae44375296ab72a/raw/c514ad8212460396813d88c6ffbdb0954c233eb5/modify-local-activation-dcom.ps1" `
-OutFile "C:\_maintainer\modify-local-activation-dcom.ps1"
Add-Content -Value "lxrun /install /y" -Path "C:\_maintainer\lxrun_install.bat"
Add-Content -Value "copy /y nul C:\_maintainer\lxrun_install_complete" -Path "C:\_maintainer\lxrun_install.bat"
# workaround to execute lxrun /install /y
$action = New-ScheduledTaskAction -Execute "C:\_maintainer\lxrun_install.bat"
$trigger = New-ScheduledTaskTrigger -AtStartup # will need to delete the task after
$setting = New-ScheduledTaskSettingsSet
$inputTask = New-ScheduledTask -action $action -settings $setting
Register-ScheduledTask Install-LXSS -InputObject $inputTask
# execute acl modification after reboot as well, sequencing shouldn't matter
$action = New-ScheduledTaskAction -Execute "powershell C:\_maintainer\modify-local-activation-dcom.ps1"
$trigger = New-ScheduledTaskTrigger -AtStartup # will need to delete the task after
$setting = New-ScheduledTaskSettingsSet
$inputTask = New-ScheduledTask -action $action -settings $setting
Register-ScheduledTask Modify-DCOM -InputObject $inputTask
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment