-
Notifications
You must be signed in to change notification settings - Fork 3
/
Remove-qBtorrent.ps1
26 lines (26 loc) · 1.15 KB
/
Remove-qBtorrent.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
Function Remove-qBtorrent {
#start session
[CmdletBinding(SupportsShouldProcess = $True)]
Param ($Password,
$Username = 'admin',
$Port = '6969'
)
Begin {
Write-Verbose "Creating Session"
#get all torrents running
[void](Invoke-RestMethod -Uri "http://localhost:$Port/login" -Body "username=admin&password=$Password" -Method Post -SessionVariable myWebSession)
}
Process {
foreach ($torrent in (Invoke-RestMethod -Uri "http://localhost:$Port/query/torrents" -Method Get -WebSession $myWebSession)) {
Write-Verbose ("Checking: {0} - {1}" -f $($torrent.name), $($torrent.progress).tostring("P"))
if ($torrent.progress -eq 1) {
#if torrent is completely downloaded delete it
if ($PSCmdlet.ShouldProcess("Remove $($torrent.name)")) {
Write-Verbose "Removing $($torrent.name)"
Invoke-RestMethod -Uri "http://localhost:$Port/command/delete" -Method Post -WebSession $myWebSession -Body "hashes=$($torrent.hash)"
}
}
}
}
}
Remove-qBtorrent -Password "foobar" -Verbose