-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwslusb.ps1
73 lines (66 loc) · 1.38 KB
/
wslusb.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# SPDX-License-Identifier: ZLib
# This script can be used to attach and detach a device to your WSL2 distribution
[CmdletBinding()]
param(
[Parameter(Mandatory= $false, HelpMessage = "Busid of the device you want to bind")]
[Alias("b")]
[string]$Busid,
[Switch]$Attach,
[Switch]$Detach,
[Switch]$List
)
# Unblock the script file
Unblock-File -Path $MyInvocation.MyCommand.Path
Function List-devices {
usbipd list
}
Function Attach-device {
param(
[string]$Busid
)
Write-Host "Attaching device $Busid"
usbipd bind --busid $Busid --force
usbipd attach --wsl --busid $Busid --auto-attach
}
Function Detach-device {
param(
[string]$Busid
)
Write-Host "Detaching device $Busid"
usbipd detach --busid $Busid
usbipd unbind --busid $Busid
}
if ($Attach -or $Detach -or $List)
{
if($List)
{
List-devices
}
if ($Detach)
{
if ($Busid)
{
Detach-device -Busid $Busid
}
else
{
Write-Host "Busid not specified"
}
}
if ($Attach)
{
if ($Busid)
{
Attach-device -Busid $Busid
}
else
{
Write-Host "Busid not specified"
}
}
}
else
{
Write-Host "No argument specified. Use -Attach, -Detach or -List"
Write-Host 'Ex: ./wslusb.ps1 -b "5-3" -Attach'
}