Skip to content

Instantly share code, notes, and snippets.

@JayDoubleu
Created February 8, 2025 13:08
Show Gist options
  • Save JayDoubleu/e6cb566738776443d3fb060a778ec2e3 to your computer and use it in GitHub Desktop.
Save JayDoubleu/e6cb566738776443d3fb060a778ec2e3 to your computer and use it in GitHub Desktop.
# Define the WSL mount command and its arguments
$wslCommand = "wsl.exe"
$wslArguments = "--mount \\.\PhysicalDrive2 --partition 1 --type ext4 --name data_wsl_shared"
# Create the scheduled task action that will run the WSL command
$action = New-ScheduledTaskAction -Execute $wslCommand -Argument $wslArguments
# Create a trigger that runs the task at system startup
$trigger = New-ScheduledTaskTrigger -AtStartup
# Register the scheduled task with a descriptive name.
# -RunLevel Highest ensures the task runs with elevated privileges.
# -User "NT AUTHORITY\SYSTEM" specifies that the task will run under the SYSTEM account.
Register-ScheduledTask -TaskName "MountWSLDrive" `
-Action $action `
-Trigger $trigger `
-RunLevel Highest `
-User "NT AUTHORITY\SYSTEM" `
-Description "Automatically mounts the WSL drive at startup."
#Register-ScheduledTask -TaskName "MountWSLDrive" -Action (New-ScheduledTaskAction -Execute "wsl.exe" -Argument "--mount \\.\PhysicalDrive2 --partition 1 --type ext4 --name data_wsl_shared") -Trigger (New-ScheduledTaskTrigger -AtStartup) -RunLevel Highest -User "NT AUTHORITY\SYSTEM" -Description "Automatically mounts the WSL drive at startup."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment