Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@rodmhgl
Last active June 23, 2020 17:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rodmhgl/877e48e06caa89beb3581e67c5f94351 to your computer and use it in GitHub Desktop.
Save rodmhgl/877e48e06caa89beb3581e67c5f94351 to your computer and use it in GitHub Desktop.
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