Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
In-progress PowerShell interface to Pi-hole API - Tested with v3.2
Function Invoke-PiHoleApi {
[CmdletBinding(
SupportsShouldProcess = $true,
ConfirmImpact = "High"
)]
param(
[ValidateSet('type', 'version', 'summaryRaw', 'summary', 'overTimeData10mins', 'recentBlocked', 'topItems', 'getQuerySources', 'getForwardDestinations', 'getQueryTypes', 'getAllQueries', 'enable', 'disable')]
[String]$Method = 'summary',
[String]$Token = 'a67cc2dccc636ec92842101cc4de47a8c8132e6688415b8a2d7230c2142db2a6',
[String]$Address = '192.168.1.18'
)
#TODO: Documentation
#TODO: Convert to Module
#TODO: topItems supports number of returned entries - topItems=25
#TODO: getQuerySources / topClients supports number of returned entries - topItems=25
#TODO: getAllQueries supports (undocumented) filters
#TODO: Separate all functions - improve return handling
$ConfirmedMethods = @('enable', 'disable')
if ($Method -in $ConfirmedMethods) {
if ($pscmdlet.ShouldProcess("$Address", $Method)) {
Invoke-RestMethod -Uri "http://$Address/admin/api.php?auth=$Token&$Method"
} else {
Write-Warning -Message "Operation Cancelled."
}
} else {
Invoke-RestMethod -Uri "http://$Address/admin/api.php?auth=$Token&$Method"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.