Last active
June 23, 2020 17:23
-
-
Save rodmhgl/877e48e06caa89beb3581e67c5f94351 to your computer and use it in GitHub Desktop.
In-progress PowerShell interface to Pi-hole API - Tested with v3.2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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