From 0e6b22a7811674f2050540c0ed47eb81dae5f679 Mon Sep 17 00:00:00 2001 From: Mike Madeja Date: Sun, 11 Oct 2026 11:09:52 -0500 Subject: [PATCH 1/7] chore: declare FunctionsToExport and add .gitattributes FunctionsToExport was missing from the manifest entirely, which PowerShell/the Gallery treat as wildcard ('*') - Microsoft's module authoring guidance calls this an anti-pattern since it forces PowerShell to execute the .psm1 to discover exports instead of reading the static manifest, and the Gallery can't show an accurate function list without importing. Added the explicit list, generated from and verified identical to PiHoleShell.psm1's own Export-ModuleMember list (76 functions, confirmed via Test-ModuleManifest and a real Import-Module). Also adds .gitattributes (* text=auto, with PiHoleShell.psd1 excluded since it's UTF-16LE). This makes line-ending normalization explicit/portable across contributors rather than implicit in each person's local core.autocrlf setting - note it does not by itself silence the "LF will be replaced by CRLF" messages this session has seen locally, since those come from this machine's own core.autocrlf=true regardless of .gitattributes. Co-Authored-By: Claude Sonnet 5 --- .gitattributes | 8 ++++++++ PiHoleShell/PiHoleShell.psd1 | Bin 1624 -> 6888 bytes 2 files changed, 8 insertions(+) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..f7f2311 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,8 @@ +# Normalize line endings for all text files based on content, rather than relying on each +# contributor's local core.autocrlf setting (which is what's been producing the "LF will be +# replaced by CRLF" warnings on every git operation in this repo). +* text=auto + +# PiHoleShell.psd1 is UTF-16LE with a BOM (New-ModuleManifest's default output) - leave it as +# binary from git's line-ending-normalization perspective so it's never rewritten. +PiHoleShell/PiHoleShell.psd1 -text diff --git a/PiHoleShell/PiHoleShell.psd1 b/PiHoleShell/PiHoleShell.psd1 index 431211d3eb965c486deb411cad1a5dd10617c8ab..9cfbe97c9914127536e111cbdc5379acc1825d9b 100644 GIT binary patch literal 6888 zcmcgxZEw>^5T4H`@gMRnpaXJPi5@&Z`^N7Uxu;| zS;`&DN1U&4Jd~;AGLlD-aJGG$?;$yZ%n-Wcr4g*{zhK9Hd@FnMP7b8Eq!W6_U)IX0 zJeD(zc7|h1p34LIfM3sXejrce1@1n>w-*@ckvzq>$H4sz#{d#f@!iUt21vSyOaZhL zU|1g4zhiwk0?tcVY$2{0Y!2iTu0Eg;f+SHk0w6@&y*wDw_x$(jACe8{Q!!5%GKW4kg!q}kHQBPoVN4~;8j!5+OP+uGu z^`CmzHaIs0LZTjkBR=c9fd_jg@?T6WZh-hcJZK|^W5j!6I1p;@B7)b*{6~2W%LO7r z&o6JKc?g{g*x+b)ya?CBrc!Nr3lDPmkeS$pe)fPMN1n+UqT`HGbkrjk$*53k8`x$z z28NY7YiK3MVY8-I_HeiOMg69z>EXVtRed z2jXYcnqZ3AR-WXhg0V7j4RmZ8EXGY?a{6yDzli2WPVgZz&2sg)oWE1-Nw_v^CW-R)88y~kZ$A*gt)zfn^;iwll>?)ya?q-p)3UN*18j>yM#OgfuO!dvMKgpmy zFtx0?mF1{!j>%;NafaPK64p+c1-}o6V^f_O=A^5*dI&}{yG@zMO3uB{8FpjgK1N3< z&v3>+R@YTty-ru+vSfPI^(EJxFYZr2pn4sdxt${loaO3$toEq}pZzrUDK@HXnRTn= z?Y@?Kfu@)8DxSNvQ)*N}J2S@-;%KN@p39p>RQ9txddlY$ZW zP;1?oW2;N-SuG})UN>UW>G@NZUN^>A=3*FQa%qe)=`_Z&^d>RJ_RPw-*s2tEf%d>q zu1s@WtLJs7$1W~Aly(hYH@1)4-M_h;bgv0ulwh+_qLWjCs z?b4d%u^kRR_YaXb%T2A#+DG)Sc69&!g8s{%vC~Y;sr(5>V~w9-h9w#_c&vpOv%l_lzRMolPRu8G%bx%5@VLqw&JVKEGVC?t z!TO-@1Z+3lzAMNe*Ft=KdA_G0yZHpd_X+F-^1a0J+kzI}=lmIs%XhB}&hOvlC-(Z= A<^TWy delta 148 zcmaE1dV`1k|33$YY6jkktg(!|6BFHm#PU`~-pSgG!9cQ>aV3ycW%34+`Ap70GFRLl zNUjExFU9Ryc^SAEcqeO0*iK%=FEY78LJUaDOkN=o1g1qKXMpKrk|kg|M5+Kti%8Wn Mfb=OqA%q7Z0ZdLNRsaA1 From 7ef1220431f184aa27e8d1162debc22910afef82 Mon Sep 17 00:00:00 2001 From: Mike Madeja Date: Mon, 12 Oct 2026 17:47:59 -0500 Subject: [PATCH 2/7] feat: add Add-PiHoleDnsRecord and Remove-PiHoleDnsRecord Adds DNS-specific convenience wrappers for managing Pi-hole's local DNS records (A/AAAA host entries and CNAME records), which were already reachable generically via Add-PiHoleConfigArrayItem / Remove-PiHoleConfigArrayItem on dns/hosts and dns/cnameRecords - these just make that discoverable with typed, DNS-specific parameters (-Type A/AAAA/CNAME, -IPv4Address, -IPv6Address, -Target, -Ttl) instead of requiring callers to know Pi-hole's raw value format (" " or ",[,]"). Both are thin wrappers that call the existing config-array functions internally rather than duplicating their auth/HTTP logic. Remove-PiHoleDnsRecord implements its own ShouldProcess and passes -Confirm:$false through to the inner call to avoid double-prompting. Co-Authored-By: Claude Sonnet 5 --- PiHoleShell/PiHoleShell.psd1 | Bin 6888 -> 7042 bytes PiHoleShell/PiHoleShell.psm1 | 2 +- .../Public/DnsControl/Add-PiHoleDnsRecord.ps1 | 147 ++++++ .../DnsControl/Remove-PiHoleDnsRecord.ps1 | 144 ++++++ README.md | 2 + docs/EXAMPLES.md | 477 +++++++++--------- .../Add-PiHoleDnsRecord.Integration.Tests.ps1 | 111 ++++ ...move-PiHoleDnsRecord.Integration.Tests.ps1 | 85 ++++ tools/Update-ExampleOutput.ps1 | 17 + 9 files changed, 756 insertions(+), 229 deletions(-) create mode 100644 PiHoleShell/Public/DnsControl/Add-PiHoleDnsRecord.ps1 create mode 100644 PiHoleShell/Public/DnsControl/Remove-PiHoleDnsRecord.ps1 create mode 100644 tests/DnsControl/Add-PiHoleDnsRecord.Integration.Tests.ps1 create mode 100644 tests/DnsControl/Remove-PiHoleDnsRecord.Integration.Tests.ps1 diff --git a/PiHoleShell/PiHoleShell.psd1 b/PiHoleShell/PiHoleShell.psd1 index 9cfbe97c9914127536e111cbdc5379acc1825d9b..296da85e69495fb923cfb6cfca96504b37a8e652 100644 GIT binary patch delta 148 zcmaE1+GM^#ihXhxyNI9*LmophLl8qMLo!1?LlHyDfL=+}Bu*Xbx5EYwjz|J+pCcom0fvZ`-B{G?fCu{RFE+zp06L%}o delta 130 zcmZoNe_^^oihXhyi`e8d99)zCuyZg5Pj2KFp8SE`YjPEb&Ex< + [CmdletBinding(HelpUri = 'https://ftl.pi-hole.net/master/docs/#put-/config/-element-/-value-')] + [Diagnostics.CodeAnalysis.SuppressMessage("PSUseShouldProcessForStateChangingFunctions", "", Justification = "Thin wrapper - Add-PiHoleConfigArrayItem (called internally) already carries this same suppression")] + [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingPlainTextForPassword", "Password")] + param ( + [Parameter(Mandatory = $true)] + [System.URI]$PiHoleServer, + [Parameter(Mandatory = $true)] + [string]$Password, + [Parameter(Mandatory = $true)] + [ValidateSet('A', 'AAAA', 'CNAME')] + [string]$Type, + [Parameter(Mandatory = $true)] + [string]$Hostname, + [string]$IPv4Address, + [string]$IPv6Address, + [string]$Target, + [Nullable[int]]$Ttl, + [Nullable[bool]]$Restart, + [bool]$IgnoreSsl = $false, + [bool]$RawOutput = $false + ) + try { + switch ($Type) { + 'A' { + if (-not $IPv4Address) { + throw "-IPv4Address is required when -Type is 'A'" + } + $ParsedAddress = $null + if (-not [System.Net.IPAddress]::TryParse($IPv4Address, [ref]$ParsedAddress) -or $ParsedAddress.AddressFamily -ne [System.Net.Sockets.AddressFamily]::InterNetwork) { + throw "'$IPv4Address' is not a valid IPv4 address" + } + $Element = 'dns/hosts' + $Value = "$IPv4Address $Hostname" + } + 'AAAA' { + if (-not $IPv6Address) { + throw "-IPv6Address is required when -Type is 'AAAA'" + } + $ParsedAddress = $null + if (-not [System.Net.IPAddress]::TryParse($IPv6Address, [ref]$ParsedAddress) -or $ParsedAddress.AddressFamily -ne [System.Net.Sockets.AddressFamily]::InterNetworkV6) { + throw "'$IPv6Address' is not a valid IPv6 address" + } + $Element = 'dns/hosts' + $Value = "$IPv6Address $Hostname" + } + 'CNAME' { + if (-not $Target) { + throw "-Target is required when -Type is 'CNAME'" + } + $Element = 'dns/cnameRecords' + $Value = "$Hostname,$Target" + if ($PSBoundParameters.ContainsKey('Ttl')) { + $Value += ",$Ttl" + } + } + } + + $InnerParams = @{ + PiHoleServer = $PiHoleServer + Password = $Password + Element = $Element + Value = $Value + IgnoreSsl = $IgnoreSsl + RawOutput = $RawOutput + } + if ($PSBoundParameters.ContainsKey('Restart')) { + $InnerParams.Restart = $Restart + } + + $Response = Add-PiHoleConfigArrayItem @InnerParams -ErrorAction Stop + + if ($RawOutput) { + Write-Output $Response + } + else { + $Object = [PSCustomObject]@{ + Type = $Type + Hostname = $Hostname + IPv4Address = $IPv4Address + IPv6Address = $IPv6Address + Target = $Target + Ttl = $Ttl + Status = $Response.Status + } + Write-Output $Object + } + } + + catch { + Write-Error -Message $_.Exception.Message + } +} diff --git a/PiHoleShell/Public/DnsControl/Remove-PiHoleDnsRecord.ps1 b/PiHoleShell/Public/DnsControl/Remove-PiHoleDnsRecord.ps1 new file mode 100644 index 0000000..bb2cf0b --- /dev/null +++ b/PiHoleShell/Public/DnsControl/Remove-PiHoleDnsRecord.ps1 @@ -0,0 +1,144 @@ +function Remove-PiHoleDnsRecord { + <# +.SYNOPSIS +Remove a local DNS record + +.DESCRIPTION +Removes a local DNS record from Pi-hole: an A record (IPv4), AAAA record (IPv6), or CNAME +record. This is a DNS-specific convenience wrapper around Remove-PiHoleConfigArrayItem, which +it calls internally - using that directly is equivalent, just less discoverable for this +specific case. + +The values given must match the record exactly as it was created (see Get-PiHoleConfig, +under .Dns.Hosts or .Dns.CnameRecords, to check the exact value if removal fails) - for a CNAME +record created with a TTL, -Ttl must be passed here too, with the same value. + +.PARAMETER PiHoleServer +The URL to the PiHole Server, for example "http://pihole.domain.com:8080", or "http://192.168.1.100" + +.PARAMETER Password +The API Password you generated from your PiHole server + +.PARAMETER Type +The kind of record to remove: A (IPv4), AAAA (IPv6), or CNAME + +.PARAMETER Hostname +The hostname of the record to remove. For -Type A or AAAA, this is the name that resolves to +the given address. For -Type CNAME, this is the alias being removed + +.PARAMETER IPv4Address +The IPv4 address the record resolves to. Required when -Type is "A" + +.PARAMETER IPv6Address +The IPv6 address the record resolves to. Required when -Type is "AAAA" + +.PARAMETER Target +The hostname the record is an alias for. Required when -Type is "CNAME" + +.PARAMETER Ttl +The TTL (in seconds) the CNAME record was created with, if any. Only used when -Type is +"CNAME" - must match exactly or the removal will not find the record + +.PARAMETER Restart +Whether to restart FTL immediately if this change requires it. Defaults to $true. Set to +$false to defer the restart, e.g. when removing several records independently rather than all +at once - you'll need to restart FTL manually later for the changes to take effect + +.PARAMETER IgnoreSsl +Set to $true to skip SSL certificate validation + +.PARAMETER RawOutput +This will dump the response instead of the formatted object + +.EXAMPLE +Remove-PiHoleDnsRecord -PiHoleServer "http://pihole.domain.com:8080" -Password "your-app-password" -Type A -Hostname "test.local" -IPv4Address "192.168.1.1" + +.EXAMPLE +Remove-PiHoleDnsRecord -PiHoleServer "http://pihole.domain.com:8080" -Password "your-app-password" -Type CNAME -Hostname "alias.local" -Target "test.local" -Ttl 300 + #> + [CmdletBinding(SupportsShouldProcess = $true, HelpUri = 'https://ftl.pi-hole.net/master/docs/#delete-/config/-element-/-value-')] + [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingPlainTextForPassword", "Password")] + param ( + [Parameter(Mandatory = $true)] + [System.URI]$PiHoleServer, + [Parameter(Mandatory = $true)] + [string]$Password, + [Parameter(Mandatory = $true)] + [ValidateSet('A', 'AAAA', 'CNAME')] + [string]$Type, + [Parameter(Mandatory = $true)] + [string]$Hostname, + [string]$IPv4Address, + [string]$IPv6Address, + [string]$Target, + [Nullable[int]]$Ttl, + [Nullable[bool]]$Restart, + [bool]$IgnoreSsl = $false, + [bool]$RawOutput = $false + ) + try { + switch ($Type) { + 'A' { + if (-not $IPv4Address) { + throw "-IPv4Address is required when -Type is 'A'" + } + $Element = 'dns/hosts' + $Value = "$IPv4Address $Hostname" + } + 'AAAA' { + if (-not $IPv6Address) { + throw "-IPv6Address is required when -Type is 'AAAA'" + } + $Element = 'dns/hosts' + $Value = "$IPv6Address $Hostname" + } + 'CNAME' { + if (-not $Target) { + throw "-Target is required when -Type is 'CNAME'" + } + $Element = 'dns/cnameRecords' + $Value = "$Hostname,$Target" + if ($PSBoundParameters.ContainsKey('Ttl')) { + $Value += ",$Ttl" + } + } + } + + if ($PSCmdlet.ShouldProcess("Pi-Hole DNS record '$Value' ($Type)", "Remove DNS record")) { + $InnerParams = @{ + PiHoleServer = $PiHoleServer + Password = $Password + Element = $Element + Value = $Value + IgnoreSsl = $IgnoreSsl + RawOutput = $RawOutput + Confirm = $false + } + if ($PSBoundParameters.ContainsKey('Restart')) { + $InnerParams.Restart = $Restart + } + + $Response = Remove-PiHoleConfigArrayItem @InnerParams -ErrorAction Stop + + if ($RawOutput) { + Write-Output $Response + } + else { + $Object = [PSCustomObject]@{ + Type = $Type + Hostname = $Hostname + IPv4Address = $IPv4Address + IPv6Address = $IPv6Address + Target = $Target + Ttl = $Ttl + Status = $Response.Status + } + Write-Output $Object + } + } + } + + catch { + Write-Error -Message $_.Exception.Message + } +} diff --git a/README.md b/README.md index e4dac0d..a12ac50 100644 --- a/README.md +++ b/README.md @@ -101,7 +101,9 @@ See [docs/EXAMPLES.md](docs/EXAMPLES.md) for real, captured output from every fu | Function | Description | |---|---| +| `Add-PiHoleDnsRecord` | Add a local DNS record | | `Get-PiHoleDnsBlockingStatus` | Get Pi-hole's current DNS blocking status | +| `Remove-PiHoleDnsRecord` | Remove a local DNS record | | `Set-PiHoleDnsBlocking` | Enable or disable Pi-hole's DNS blocking | ### Group Management diff --git a/docs/EXAMPLES.md b/docs/EXAMPLES.md index 0602c4e..3859b32 100644 --- a/docs/EXAMPLES.md +++ b/docs/EXAMPLES.md @@ -86,6 +86,40 @@ Set-PiHoleDnsBlocking -PiHoleServer $PiHoleServer -Password $Password -Blocking _Not captured this run - re-run with -IncludeDisruptive to include a live example._ ``` +### Add-PiHoleDnsRecord + +```powershell +Add-PiHoleDnsRecord -PiHoleServer $PiHoleServer -Password $Password -Type A -Hostname "piholeshell-docs-dns-example.com" -IPv4Address "192.0.2.2" +``` + +``` + +Type : A +Hostname : piholeshell-docs-dns-example.com +IPv4Address : 192.0.2.2 +IPv6Address : +Target : +Ttl : +Status : Added +``` + +### Remove-PiHoleDnsRecord + +```powershell +Remove-PiHoleDnsRecord -PiHoleServer $PiHoleServer -Password $Password -Type A -Hostname "piholeshell-docs-dns-example.com" -IPv4Address "192.0.2.2" +``` + +``` + +Type : A +Hostname : piholeshell-docs-dns-example.com +IPv4Address : 192.0.2.2 +IPv6Address : +Target : +Ttl : +Status : Removed +``` + ## Group Management ### New-PiHoleGroup @@ -99,9 +133,9 @@ New-PiHoleGroup -PiHoleServer $PiHoleServer -Password $Password -GroupName "PiHo Name : PiHoleShellDocsExampleGroup Comment : Example group Enabled : True -Id : 63 -DateAdded : 10/6/2026 10:06:30 PM -DateModified : 10/6/2026 10:06:30 PM +Id : 62 +DateAdded : 10/12/2026 5:37:04 PM +DateModified : 10/12/2026 5:37:04 PM ``` ### Get-PiHoleGroup @@ -143,9 +177,9 @@ DateModified : 9/30/2026 8:48:26 AM Name : PiHoleShellDocsExampleGroup Comment : Example group Enabled : True -Id : 63 -DateAdded : 10/6/2026 10:06:30 PM -DateModified : 10/6/2026 10:06:30 PM +Id : 62 +DateAdded : 10/12/2026 5:37:04 PM +DateModified : 10/12/2026 5:37:04 PM ``` ### Update-PiHoleGroup @@ -159,9 +193,9 @@ Update-PiHoleGroup -PiHoleServer $PiHoleServer -Password $Password -GroupName "P Name : PiHoleShellDocsExampleGroup Comment : Example group Enabled : False -Id : 63 -DateAdded : 10/6/2026 10:06:30 PM -DateModified : 10/6/2026 10:06:48 PM +Id : 62 +DateAdded : 10/12/2026 5:37:04 PM +DateModified : 10/12/2026 5:37:22 PM ``` ### Remove-PiHoleGroup @@ -190,9 +224,9 @@ Address : https://blocklistproject.github.io/Lists/alt-version/ransomware Comment : Example list Groups : {Default} Enabled : True -Id : 81 -DateAdded : 10/6/2026 10:07:25 PM -DateModified : 10/6/2026 10:07:25 PM +Id : 79 +DateAdded : 10/12/2026 5:37:59 PM +DateModified : 10/12/2026 5:37:59 PM Type : Block DateUpdated : Number : 0 @@ -218,7 +252,7 @@ DateAdded : 7/6/2025 2:20:13 AM DateModified : 7/6/2025 2:20:13 AM Type : block DateUpdated : 7/6/2025 2:20:13 AM -Number : 72234 +Number : 72526 InvalidDomains : 1 AbpEntries : 0 Status : 2 @@ -246,7 +280,7 @@ DateAdded : 7/6/2025 2:20:46 AM DateModified : 7/6/2025 2:20:46 AM Type : block DateUpdated : 7/6/2025 2:20:46 AM -Number : 176582 +Number : 178722 InvalidDomains : 0 AbpEntries : 0 Status : 2 @@ -294,9 +328,9 @@ Address : https://blocklistproject.github.io/Lists/alt-version/ransomware Comment : Example list Groups : {Default} Enabled : False -Id : 81 -DateAdded : 10/6/2026 10:07:25 PM -DateModified : 10/6/2026 10:07:58 PM +Id : 79 +DateAdded : 10/12/2026 5:37:59 PM +DateModified : 10/12/2026 5:38:32 PM Type : Block DateUpdated : Number : 0 @@ -322,8 +356,8 @@ Type : block Groups : {0} DateAdded : 7/6/2025 2:20:13 AM DateModified : 7/6/2025 2:20:13 AM -DateUpdated : 10/2/2026 9:10:24 PM -Number : 72234 +DateUpdated : 10/7/2026 4:41:49 PM +Number : 72526 InvalidDomains : 1 AbpEntries : 0 Status : 2 @@ -352,8 +386,8 @@ Type : block Groups : {0} DateAdded : 7/6/2025 2:20:46 AM DateModified : 7/6/2025 2:20:46 AM -DateUpdated : 10/2/2026 9:43:40 AM -Number : 176582 +DateUpdated : 10/10/2026 7:37:55 PM +Number : 178722 InvalidDomains : 0 AbpEntries : 0 Status : 2 @@ -421,9 +455,9 @@ Kind : Exact Comment : Example domain Groups : {Default} Enabled : True -Id : 18 -DateAdded : 10/6/2026 10:08:36 PM -DateModified : 10/6/2026 10:08:36 PM +Id : 16 +DateAdded : 10/12/2026 5:39:10 PM +DateModified : 10/12/2026 5:39:10 PM ``` ### Get-PiHoleDomain @@ -441,9 +475,9 @@ Kind : exact Comment : Example domain Groups : {Default} Enabled : True -Id : 18 -DateAdded : 10/6/2026 10:08:36 PM -DateModified : 10/6/2026 10:08:36 PM +Id : 16 +DateAdded : 10/12/2026 5:39:10 PM +DateModified : 10/12/2026 5:39:10 PM ``` ### Update-PiHoleDomain @@ -461,9 +495,9 @@ Kind : Exact Comment : Example domain Groups : {Default} Enabled : False -Id : 18 -DateAdded : 10/6/2026 10:08:36 PM -DateModified : 10/6/2026 10:09:10 PM +Id : 16 +DateAdded : 10/12/2026 5:39:10 PM +DateModified : 10/12/2026 5:39:44 PM ``` ### Remove-PiHoleDomain @@ -494,9 +528,9 @@ Client : 192.168.99.99 Name : Comment : Example client Groups : {Default} -Id : 20 -DateAdded : 10/6/2026 10:09:40 PM -DateModified : 10/6/2026 10:09:40 PM +Id : 18 +DateAdded : 10/12/2026 5:40:15 PM +DateModified : 10/12/2026 5:40:15 PM ``` ### Get-PiHoleClient @@ -511,9 +545,9 @@ Client : 192.168.99.99 Name : Comment : Example client Groups : {Default} -Id : 20 -DateAdded : 10/6/2026 10:09:40 PM -DateModified : 10/6/2026 10:09:40 PM +Id : 18 +DateAdded : 10/12/2026 5:40:15 PM +DateModified : 10/12/2026 5:40:15 PM ``` ### Get-PiHoleClientSuggestion @@ -526,13 +560,13 @@ Get-PiHoleClientSuggestion -PiHoleServer $PiHoleServer -Password $Password HwAddr : ip-127.0.0.1 MacVendor : -LastQuery : 10/6/2026 10:06:14 PM +LastQuery : 10/12/2026 5:36:48 PM Addresses : 127.0.0.1 Names : localhost HwAddr : 74:56:3c:bb:f4:0b MacVendor : Giga-Byte Technology Co.,Ltd. -LastQuery : 10/6/2026 10:03:16 PM +LastQuery : 10/12/2026 5:27:24 PM Addresses : 192.168.1.162 Names : ``` @@ -549,9 +583,9 @@ Client : 192.168.99.99 Name : Comment : Updated comment Groups : {Default} -Id : 20 -DateAdded : 10/6/2026 10:09:40 PM -DateModified : 10/6/2026 10:10:18 PM +Id : 18 +DateAdded : 10/12/2026 5:40:15 PM +DateModified : 10/12/2026 5:40:53 PM ``` ### Remove-PiHoleClient @@ -576,18 +610,18 @@ Get-PiHoleStatsSummary -PiHoleServer $PiHoleServer -Password $Password ``` -Total : 72 -Blocked : 8 -PercentBlocked : 11.1111106872559 -UniqueDomains : 16 -Forwarded : 27 -Cached : 37 +Total : 310 +Blocked : 92 +PercentBlocked : 29.6774196624756 +UniqueDomains : 22 +Forwarded : 66 +Cached : 152 Frequency : 0 -Types : @{A=18; AAAA=17; ANY=0; SRV=0; SOA=0; PTR=37; TXT=0; NAPTR=0; MX=0; DS=0; RRSIG=0; DNSKEY=0; NS=0; SVCB=0; HTTPS=0; OTHER=0} -Status : @{Unknown=0; Gravity=8; Forwarded=27; Cache=37; Regex=0; DenyList=0; ExternalBlockedIp=0; ExternalBlockedNull=0; ExternalBlockedNxra=0; GravityCname=0; RegexCname=0; DenyListCname=0; Retired=0; RetiredDnssec=0; InProgress=0; Dbbusy=0; SpecialDomain=0; CacheStale=0; ExternalBlockedEde15=0} -Replies : @{Unknown=7; Nodata=3; Nxdomain=2; Cname=0; Ip=25; Domain=35; Rrname=0; ServFail=0; Refused=0; Notimp=0; Other=0; Dnssec=0; None=0; Blob=0} +Types : @{A=145; AAAA=145; ANY=0; SRV=0; SOA=0; PTR=20; TXT=0; NAPTR=0; MX=0; DS=0; RRSIG=0; DNSKEY=0; NS=0; SVCB=0; HTTPS=0; OTHER=0} +Status : @{Unknown=0; Gravity=92; Forwarded=66; Cache=122; Regex=0; DenyList=0; ExternalBlockedIp=0; ExternalBlockedNull=0; ExternalBlockedNxra=0; GravityCname=0; RegexCname=0; DenyListCname=0; Retired=0; RetiredDnssec=0; InProgress=0; Dbbusy=0; SpecialDomain=0; CacheStale=30; ExternalBlockedEde15=0} +Replies : @{Unknown=22; Nodata=23; Nxdomain=5; Cname=0; Ip=245; Domain=15; Rrname=0; ServFail=0; Refused=0; Notimp=0; Other=0; Dnssec=0; None=0; Blob=0} Clients : @{Active=2; Total=2} -Gravity : @{DomainsBeingBlocked=526957; LastUpdate=1791140144} +Gravity : @{DomainsBeingBlocked=560453; LastUpdate=1791840963} ``` ### Get-PiHoleStatsRecentBlocked @@ -598,7 +632,7 @@ Get-PiHoleStatsRecentBlocked -PiHoleServer $PiHoleServer -Password $Password ``` -Blocked : googlesyndication.com +Blocked : ads.pubmatic.com ``` ### Get-PiHoleStatsQueryType @@ -610,10 +644,10 @@ Get-PiHoleStatsQueryType -PiHoleServer $PiHoleServer -Password $Password ``` Type : A -Count : 18 +Count : 145 Type : AAAA -Count : 17 +Count : 145 Type : ANY Count : 0 @@ -635,20 +669,20 @@ Get-PiHoleStatsTopDomain -PiHoleServer $PiHoleServer -Password $Password ``` -Domain : 1.0.0.127.in-addr.arpa -Count : 31 - -Domain : bbc.com -Count : 4 +Domain : github.com +Count : 25 Domain : example.com -Count : 4 +Count : 22 + +Domain : reddit.com +Count : 22 Domain : python.org -Count : 4 +Count : 19 -Domain : wikipedia.org -Count : 4 +Domain : mozilla.org +Count : 18 _(showing 5 of 10 results)_ ``` @@ -661,13 +695,13 @@ Get-PiHoleStatsTopClient -PiHoleServer $PiHoleServer -Password $Password ``` -IP : 127.0.0.1 -Name : localhost -Count : 37 - IP : 192.168.1.162 Name : -Count : 35 +Count : 290 + +IP : 127.0.0.1 +Name : localhost +Count : 20 ``` ### Get-PiHoleStatsUpstream @@ -678,9 +712,9 @@ Get-PiHoleStatsUpstream -PiHoleServer $PiHoleServer -Password $Password ``` -TotalQueries : 72 -ForwardedQueries : 27 -Upstreams : {@{Ip=blocklist; Name=blocklist; Port=-1; Count=8; ResponseTime=0; Variance=0}, @{Ip=cache; Name=cache; Port=-1; Count=37; ResponseTime=0; Variance=0}, @{Ip=8.8.4.4; Name=dns.google; Port=53; Count=23; ResponseTime=0; Variance=0}, @{Ip=8.8.8.8; Name=dns.google; Port=53; Count=4; ResponseTime=0; Variance=0}} +TotalQueries : 310 +ForwardedQueries : 66 +Upstreams : {@{Ip=blocklist; Name=blocklist; Port=-1; Count=92; ResponseTime=0; Variance=0}, @{Ip=cache; Name=cache; Port=-1; Count=152; ResponseTime=0; Variance=0}, @{Ip=8.8.4.4; Name=dns.google; Port=53; Count=59; ResponseTime=0; Variance=0}, @{Ip=8.8.8.8; Name=dns.google; Port=53; Count=7; ResponseTime=0; Variance=0}} ``` ### Get-PiHoleStatsQuerySuggestions @@ -691,8 +725,8 @@ Get-PiHoleStatsQuerySuggestions -PiHoleServer $PiHoleServer -Password $Password ``` -Domain : {1.0.0.127.in-addr.arpa, bbc.com, example.com, python.org…} -ClientIp : {127.0.0.1, 192.168.1.162} +Domain : {github.com, example.com, reddit.com, python.org…} +ClientIp : {192.168.1.162, 127.0.0.1} ClientName : {localhost} Upstream : {blocklist, cache, 8.8.4.4#53 (dns.google), 8.8.8.8#53 (dns.google)…} Type : {A, AAAA, ANY, SRV…} @@ -711,10 +745,10 @@ Get-PiHoleStatsDatabaseSummary -PiHoleServer $PiHoleServer -Password $Password ``` -SumQueries : 56 -SumBlocked : 8 -PercentBlocked : 14.2857141494751 -TotalClients : 2 +SumQueries : 310 +SumBlocked : 92 +PercentBlocked : 29.6774196624756 +TotalClients : 3 ``` ### Get-PiHoleStatsDatabaseQueryType @@ -728,7 +762,7 @@ Get-PiHoleStatsDatabaseQueryType -PiHoleServer $PiHoleServer -Password $Password ``` Type : A -Count : 17 +Count : 145 Type : AAAA Count : 0 @@ -740,7 +774,7 @@ Type : SRV Count : 0 Type : SOA -Count : 21 +Count : 20 _(showing 5 of 16 results)_ ``` @@ -755,20 +789,20 @@ Get-PiHoleStatsDatabaseTopDomain -PiHoleServer $PiHoleServer -Password $Password ``` -Domain : 1.0.0.127.in-addr.arpa -Count : 15 +Domain : github.com +Count : 25 -Domain : python.org -Count : 4 +Domain : example.com +Count : 22 -Domain : bbc.com -Count : 4 +Domain : reddit.com +Count : 22 -Domain : wikipedia.org -Count : 4 +Domain : python.org +Count : 19 -Domain : example.com -Count : 4 +Domain : mozilla.org +Count : 18 _(showing 5 of 10 results)_ ``` @@ -785,11 +819,15 @@ Get-PiHoleStatsDatabaseTopClient -PiHoleServer $PiHoleServer -Password $Password IP : 192.168.1.162 Name : -Count : 27 +Count : 198 IP : 127.0.0.1 Name : localhost -Count : 21 +Count : 17 + +IP : 127.0.0.1 +Name : +Count : 3 ``` ### Get-PiHoleStatsDatabaseUpstream @@ -802,9 +840,9 @@ Get-PiHoleStatsDatabaseUpstream -PiHoleServer $PiHoleServer -Password $Password ``` -TotalQueries : 56 -ForwardedQueries : 27 -Upstreams : {@{Ip=1; Name=; Port=-1; Count=23; ResponseTime=0; Variance=0}, @{Ip=2; Name=; Port=-1; Count=4; ResponseTime=0; Variance=0}, @{Ip=cache; Name=cache; Port=-1; Count=21; ResponseTime=0; Variance=0}, @{Ip=blocklist; Name=blocklist; Port=-1; Count=8; ResponseTime=0; Variance=0}} +TotalQueries : 310 +ForwardedQueries : 66 +Upstreams : {@{Ip=1; Name=; Port=-1; Count=59; ResponseTime=0; Variance=0}, @{Ip=2; Name=; Port=-1; Count=7; ResponseTime=0; Variance=0}, @{Ip=cache; Name=cache; Port=-1; Count=122; ResponseTime=0; Variance=0}, @{Ip=blocklist; Name=blocklist; Port=-1; Count=122; ResponseTime=0; Variance=0}} ``` ### Get-PiHoleQuery @@ -817,67 +855,67 @@ Get-PiHoleQuery -PiHoleServer $PiHoleServer -Password $Password -Length 5 ``` -Id : 394 -Time : 10/6/2026 10:06:15 PM +Id : 309 +Time : 10/12/2026 5:36:49 PM Type : PTR Domain : 4.4.8.8.in-addr.arpa Cname : Status : FORWARDED Client : @{Ip=127.0.0.1; Name=localhost} Dnssec : UNKNOWN -Reply : @{Type=DOMAIN; Time=0.0241849422454834} +Reply : @{Type=DOMAIN; Time=0.0182390213012695} ListId : -Upstream : 8.8.8.8#53 +Upstream : 8.8.4.4#53 Ede : @{Code=-1; Text=} -Id : 393 -Time : 10/6/2026 10:06:15 PM +Id : 308 +Time : 10/12/2026 5:36:49 PM Type : PTR Domain : 8.8.8.8.in-addr.arpa Cname : Status : FORWARDED Client : @{Ip=127.0.0.1; Name=localhost} Dnssec : UNKNOWN -Reply : @{Type=DOMAIN; Time=0.0249054431915283} +Reply : @{Type=DOMAIN; Time=0.0416350364685059} ListId : -Upstream : 8.8.8.8#53 +Upstream : 8.8.4.4#53 Ede : @{Code=-1; Text=} -Id : 392 -Time : 10/6/2026 10:06:15 PM +Id : 307 +Time : 10/12/2026 5:36:49 PM Type : PTR -Domain : 162.1.168.192.in-addr.arpa +Domain : 1.0.0.127.in-addr.arpa Cname : Status : CACHE Client : @{Ip=127.0.0.1; Name=localhost} Dnssec : UNKNOWN -Reply : @{Type=NXDOMAIN; Time=0.0157008171081543} +Reply : @{Type=DOMAIN; Time=0.00114893913269043} ListId : Upstream : Ede : @{Code=-1; Text=} -Id : 391 -Time : 10/6/2026 10:06:15 PM +Id : 306 +Time : 10/12/2026 5:36:49 PM Type : PTR -Domain : 1.0.0.127.in-addr.arpa +Domain : 162.1.168.192.in-addr.arpa Cname : Status : CACHE Client : @{Ip=127.0.0.1; Name=localhost} Dnssec : UNKNOWN -Reply : @{Type=DOMAIN; Time=0.0260829925537109} +Reply : @{Type=NXDOMAIN; Time=0.0187718868255615} ListId : Upstream : Ede : @{Code=-1; Text=} -Id : 390 -Time : 10/6/2026 10:03:17 PM +Id : 305 +Time : 10/12/2026 5:28:23 PM Type : PTR Domain : 4.4.8.8.in-addr.arpa Cname : Status : FORWARDED Client : @{Ip=127.0.0.1; Name=localhost} Dnssec : UNKNOWN -Reply : @{Type=DOMAIN; Time=0.0180368423461914} +Reply : @{Type=DOMAIN; Time=0.0437800884246826} ListId : Upstream : 8.8.4.4#53 Ede : @{Code=-1; Text=} @@ -992,20 +1030,20 @@ CpuPercent : 0 MemoryPercent : 0 ActiveClients : 2 Blocking : enabled -Cache : @{Size=10000; Inserted=34; Evicted=0} +Cache : @{Size=10000; Inserted=2; Evicted=0} Config : @{DhcpActive=False; DhcpStart=; DhcpEnd=; DhcpIpv6=False; DnsDnssec=False; DnsDomain=lan; DnsNumUpstreams=2; DnsPort=53; DnsrevServerAactive=False; PrivacyLevel=0} -GravitySize : 526957 +GravitySize : 560453 HostModel : Raspberry Pi Zero W Rev 1.1 IFace : @{v4=; v6=} NodeName : dns3.localdomain -Pid : 389 -Queries : @{Total=69; Blocked=8; PercentBlocked=11.5942029953003; QueryFrequency=0} -RecentBlocked : googlesyndication.com -Sensors : @{CpuTemp=40.622; HotLimit=60; Unit=C} -System : @{Uptime=384699; Memory=; Procs=70; Cpu=; Ftl=} -TopBlocked : analytics.google.com +Pid : 388 +Queries : @{Total=306; Blocked=92; PercentBlocked=30.0653591156006; QueryFrequency=0} +RecentBlocked : ads.pubmatic.com +Sensors : @{CpuTemp=41.698; HotLimit=60; Unit=C} +System : @{Uptime=152421; Memory=; Procs=73; Cpu=; Ftl=} +TopBlocked : googleadservices.com TopClient : 192.168.1.162 -TopDomain : 1.0.0.127.in-addr.arpa +TopDomain : github.com Version : @{Core=; Web=; Ftl=; Docker=} ``` @@ -1042,11 +1080,11 @@ Get-PiHoleInfoSystem -PiHoleServer $PiHoleServer -Password $Password ``` -Uptime : 384709 +Uptime : 152431 Memory : @{Ram=; Swap=} -Procs : 70 -Cpu : @{NumProcessors=1; PercentCpu=96.8000030517578; Load=} -Ftl : @{PercentMemory=3.02243185043335; PercentCpu=96.5} +Procs : 73 +Cpu : @{NumProcessors=1; PercentCpu=95.3000030517578; Load=} +Ftl : @{PercentMemory=2.54814767837524; PercentCpu=94.9000015258789} ``` ### Get-PiHoleInfoFtl @@ -1057,16 +1095,16 @@ Get-PiHoleInfoFtl -PiHoleServer $PiHoleServer -Password $Password ``` -Database : @{Gravity=526957; Antigravity=0; Groups=4; Lists=14; Clients=0; Domains=; Regex=} +Database : @{Gravity=560453; Antigravity=0; Groups=4; Lists=14; Clients=0; Domains=; Regex=} PrivacyLevel : 0 QueryFrequency : 0 Clients : @{Total=2; Active=2} -Pid : 389 -Uptime : 528324.275473 -PercentMemory : 3.02243185043335 -PercentCpu : 96.5 +Pid : 388 +Uptime : 442841.840855 +PercentMemory : 2.54814767837524 +PercentCpu : 95.6999969482422 AllowDestructive : True -Dnsmasq : @{DnsCacheInserted=34; DnsCacheLiveFreed=0; DnsQueriesForwarded=25; DnsAuthAnswered=0; DnsLocalAnswered=15; DnsStaleAnswered=0; DnsUnanswered=0; DnssecMaxCryptoUse=0; DnssecMaxSigFail=0; DnssecMaxWork=0; Bootp=0; Pxe=0; DhcpAck=0; DhcpDecline=0; DhcpDiscover=0; DhcpInform=0; DhcpNak=0; DhcpOffer=0; DhcpRelease=0; DhcpRequest=0; Noanswer=0; LeasesAllocated4=0; LeasesPruned4=0; LeasesAllocated6=0; LeasesPruned6=0; TcpConnections=0; DhcpLeasequery=0; DhcpLeaseUnassigned=0; DhcpLeaseActve=0; DhcpLeaseUnknown=0} +Dnsmasq : @{DnsCacheInserted=2; DnsCacheLiveFreed=0; DnsQueriesForwarded=2; DnsAuthAnswered=0; DnsLocalAnswered=2; DnsStaleAnswered=0; DnsUnanswered=0; DnssecMaxCryptoUse=0; DnssecMaxSigFail=0; DnssecMaxWork=0; Bootp=0; Pxe=0; DhcpAck=0; DhcpDecline=0; DhcpDiscover=0; DhcpInform=0; DhcpNak=0; DhcpOffer=0; DhcpRelease=0; DhcpRequest=0; Noanswer=0; LeasesAllocated4=0; LeasesPruned4=0; LeasesAllocated6=0; LeasesPruned6=0; TcpConnections=0; DhcpLeasequery=0; DhcpLeaseUnassigned=0; DhcpLeaseActve=0; DhcpLeaseUnknown=0} ``` ### Get-PiHoleInfoSensors @@ -1078,7 +1116,7 @@ Get-PiHoleInfoSensors -PiHoleServer $PiHoleServer -Password $Password ``` List : {@{Name=cpu_thermal; Path=hwmon0; Source=devices/virtual/thermal/thermal_zone0; Temps=}, @{Name=rpi_volt; Path=hwmon1; Source=devices/platform/soc/soc:firmware/raspberrypi-hwmon; Temps=}} -CpuTemp : 41.16 +CpuTemp : 41.698 HotLimit : 60 Unit : C ``` @@ -1095,13 +1133,13 @@ Size : 13983744 Type : Regular file Mode : rw-r----- AccessTime : 6/25/2025 12:32:44 AM -ModifiedTime : 10/6/2026 9:56:20 PM -ChangeTime : 10/6/2026 9:56:20 PM +ModifiedTime : 10/12/2026 5:28:19 PM +ChangeTime : 10/12/2026 5:28:19 PM Owner : @{User=; Group=} -Queries : 69 -EarliestTimestamp : 10/5/2026 10:00:00 PM -QueriesDisk : 391 -EarliestTimestampDisk : 10/4/2026 2:31:09 PM +Queries : 306 +EarliestTimestamp : 10/11/2026 5:30:00 PM +QueriesDisk : 306 +EarliestTimestampDisk : 10/12/2026 5:12:02 PM SqliteVersion : 3.53.1 ``` @@ -1168,7 +1206,12 @@ Get-PiHoleInfoMessage -PiHoleServer $PiHoleServer -Password $Password ``` ``` -(no output) + +Id : 1 +Timestamp : 10/12/2026 5:28:21 PM +Type : LOAD +Plain : Long-term load (15min avg) larger than number of processors: 1.2 > 1 +Html : Long-term load (15min avg) larger than number of processors: 1.2 > 1
This may slow down DNS resolution and can cause bottlenecks. ``` ### Get-PiHoleInfoMessageCount @@ -1179,7 +1222,7 @@ Get-PiHoleInfoMessageCount -PiHoleServer $PiHoleServer -Password $Password ``` -Count : 0 +Count : 1 ``` ### Remove-PiHoleInfoMessage @@ -1203,9 +1246,9 @@ Get-PiHoleLogWebserver -PiHoleServer $PiHoleServer -Password $Password ``` -Log : {@{Timestamp=10/6/2026 9:56:22 PM; Message=Initializing HTTP server on ports "8089,8489s"; Priority=}, @{Timestamp=10/6/2026 10:04:28 PM; Message=ACCESS: 192.168.1.162 - - [07/Oct/2026:03:04:27 +0000] "PATCH /api/config?restart=false HTTP/1.1" 200 4588 - Mozilla/5.0 (Windows NT 10.0; Microsoft Windows 10.0.26200; en-US) PowerShell/7.6.6; Priority=}, @{Timestamp=10/6/2026 10:04:29 PM; Message=ACCESS: 192.168.1.162 - - [07/Oct/2026:03:04:28 +0000] "DELETE /api/auth HTTP/1.1" 204 558 - Mozilla/5.0 (Windows NT 10.0; Microsoft Windows 10.0.26200; en-US) PowerShell/7.6.6; Priority=}, @{Timestamp=10/6/2026 10:04:33 PM; Message=ACCESS: 192.168.1.162 - - [07/Oct/2026:03:04:28 +0000] "POST /api/auth HTTP/1.1" 200 808 - Mozilla/5.0 (Windows NT 10.0; Microsoft Windows 10.0.26200; en-US) PowerShell/7.6.6; Priority=}} +Log : {@{Timestamp=10/12/2026 5:28:21 PM; Message=Initializing HTTP server on ports "8089,8489s"; Priority=}, @{Timestamp=10/12/2026 5:34:46 PM; Message=ACCESS: 192.168.1.162 - - [12/Oct/2026:22:34:45 +0000] "PATCH /api/config?restart=false HTTP/1.1" 200 4589 - Mozilla/5.0 (Windows NT 10.0; Microsoft Windows 10.0.26200; en-US) PowerShell/7.6.6; Priority=}, @{Timestamp=10/12/2026 5:34:46 PM; Message=ACCESS: 192.168.1.162 - - [12/Oct/2026:22:34:46 +0000] "DELETE /api/auth HTTP/1.1" 204 558 - Mozilla/5.0 (Windows NT 10.0; Microsoft Windows 10.0.26200; en-US) PowerShell/7.6.6; Priority=}, @{Timestamp=10/12/2026 5:34:51 PM; Message=ACCESS: 192.168.1.162 - - [12/Oct/2026:22:34:46 +0000] "POST /api/auth HTTP/1.1" 200 806 - Mozilla/5.0 (Windows NT 10.0; Microsoft Windows 10.0.26200; en-US) PowerShell/7.6.6; Priority=}} NextID : 4 -Pid : 389 +Pid : 388 File : /var/log/pihole/webserver.log ``` @@ -1217,9 +1260,9 @@ Get-PiHoleLogDnsmasq -PiHoleServer $PiHoleServer -Password $Password ``` -Log : {@{Timestamp=10/6/2026 9:56:22 PM; Message=started, version pi-hole-v2.93 cachesize 10000; Priority=}, @{Timestamp=10/6/2026 9:56:22 PM; Message=DNS service limited to local subnets; Priority=}, @{Timestamp=10/6/2026 9:56:22 PM; Message=compile time options: IPv6 GNU-getopt no-DBus no-UBus no-i18n IDN2 DHCP DHCPv6 Lua TFTP no-conntrack ipset no-nftset auth DNSSEC loop-detect inotify dumpfile; Priority=}, @{Timestamp=10/6/2026 9:56:22 PM; Message=using nameserver 8.8.8.8#53; Priority=}…} -NextID : 21 -Pid : 389 +Log : {@{Timestamp=10/12/2026 5:28:21 PM; Message=started, version pi-hole-v2.93 cachesize 10000; Priority=}, @{Timestamp=10/12/2026 5:28:21 PM; Message=DNS service limited to local subnets; Priority=}, @{Timestamp=10/12/2026 5:28:21 PM; Message=compile time options: IPv6 GNU-getopt no-DBus no-UBus no-i18n IDN2 DHCP DHCPv6 Lua TFTP no-conntrack ipset no-nftset auth DNSSEC loop-detect inotify dumpfile; Priority=}, @{Timestamp=10/12/2026 5:28:21 PM; Message=using nameserver 8.8.8.8#53; Priority=}…} +NextID : 51 +Pid : 388 File : /var/log/pihole/pihole.log ``` @@ -1231,9 +1274,9 @@ Get-PiHoleLogFtl -PiHoleServer $PiHoleServer -Password $Password ``` -Log : {@{Timestamp=10/6/2026 9:56:21 PM; Message=PID of FTL process: 389; Priority=INFO}, @{Timestamp=10/6/2026 9:56:21 PM; Message=listening on 0.0.0.0 port 53; Priority=INFO}, @{Timestamp=10/6/2026 9:56:21 PM; Message=listening on :: port 53; Priority=INFO}, @{Timestamp=10/6/2026 9:56:21 PM; Message=Database version is 22; Priority=INFO}…} -NextID : 109 -Pid : 389 +Log : {@{Timestamp=10/12/2026 5:28:20 PM; Message=PID of FTL process: 388; Priority=INFO}, @{Timestamp=10/12/2026 5:28:20 PM; Message=listening on 0.0.0.0 port 53; Priority=INFO}, @{Timestamp=10/12/2026 5:28:20 PM; Message=listening on :: port 53; Priority=INFO}, @{Timestamp=10/12/2026 5:28:20 PM; Message=Database version is 22; Priority=INFO}…} +NextID : 180 +Pid : 388 File : /var/log/pihole/FTL.log ``` @@ -1274,31 +1317,31 @@ Get-PiHoleHistory -PiHoleServer $PiHoleServer -Password $Password ``` -Timestamp : 10/5/2026 10:15:00 PM +Timestamp : 10/11/2026 5:45:00 PM Total : 0 Cached : 0 Blocked : 0 Forwarded : 0 -Timestamp : 10/5/2026 10:25:00 PM +Timestamp : 10/11/2026 5:55:00 PM Total : 0 Cached : 0 Blocked : 0 Forwarded : 0 -Timestamp : 10/5/2026 10:35:00 PM +Timestamp : 10/11/2026 6:05:00 PM Total : 0 Cached : 0 Blocked : 0 Forwarded : 0 -Timestamp : 10/5/2026 10:45:00 PM +Timestamp : 10/11/2026 6:15:00 PM Total : 0 Cached : 0 Blocked : 0 Forwarded : 0 -Timestamp : 10/5/2026 10:55:00 PM +Timestamp : 10/11/2026 6:25:00 PM Total : 0 Cached : 0 Blocked : 0 @@ -1315,20 +1358,20 @@ Get-PiHoleHistoryClient -PiHoleServer $PiHoleServer -Password $Password ``` -Timestamp : 10/5/2026 10:15:00 PM -Clients : {@{IP=127.0.0.1; Name=localhost; Count=0}, @{IP=192.168.1.162; Name=; Count=0}, @{IP=others; Name=; Count=0}} +Timestamp : 10/11/2026 5:45:00 PM +Clients : {@{IP=192.168.1.162; Name=; Count=0}, @{IP=127.0.0.1; Name=localhost; Count=0}, @{IP=others; Name=; Count=0}} -Timestamp : 10/5/2026 10:25:00 PM -Clients : {@{IP=127.0.0.1; Name=localhost; Count=0}, @{IP=192.168.1.162; Name=; Count=0}, @{IP=others; Name=; Count=0}} +Timestamp : 10/11/2026 5:55:00 PM +Clients : {@{IP=192.168.1.162; Name=; Count=0}, @{IP=127.0.0.1; Name=localhost; Count=0}, @{IP=others; Name=; Count=0}} -Timestamp : 10/5/2026 10:35:00 PM -Clients : {@{IP=127.0.0.1; Name=localhost; Count=0}, @{IP=192.168.1.162; Name=; Count=0}, @{IP=others; Name=; Count=0}} +Timestamp : 10/11/2026 6:05:00 PM +Clients : {@{IP=192.168.1.162; Name=; Count=0}, @{IP=127.0.0.1; Name=localhost; Count=0}, @{IP=others; Name=; Count=0}} -Timestamp : 10/5/2026 10:45:00 PM -Clients : {@{IP=127.0.0.1; Name=localhost; Count=0}, @{IP=192.168.1.162; Name=; Count=0}, @{IP=others; Name=; Count=0}} +Timestamp : 10/11/2026 6:15:00 PM +Clients : {@{IP=192.168.1.162; Name=; Count=0}, @{IP=127.0.0.1; Name=localhost; Count=0}, @{IP=others; Name=; Count=0}} -Timestamp : 10/5/2026 10:55:00 PM -Clients : {@{IP=127.0.0.1; Name=localhost; Count=0}, @{IP=192.168.1.162; Name=; Count=0}, @{IP=others; Name=; Count=0}} +Timestamp : 10/11/2026 6:25:00 PM +Clients : {@{IP=192.168.1.162; Name=; Count=0}, @{IP=127.0.0.1; Name=localhost; Count=0}, @{IP=others; Name=; Count=0}} _(showing 5 of 145 results)_ ``` @@ -1343,37 +1386,23 @@ Get-PiHoleHistoryDatabase -PiHoleServer $PiHoleServer -Password $Password ``` -Timestamp : 10/6/2026 3:00:00 PM -Total : 1 -Cached : 1 -Blocked : 0 -Forwarded : 0 - -Timestamp : 10/6/2026 4:00:00 PM -Total : 1 -Cached : 1 -Blocked : 0 -Forwarded : 0 +Timestamp : 10/12/2026 5:10:00 PM +Total : 50 +Cached : 14 +Blocked : 2 +Forwarded : 34 -Timestamp : 10/6/2026 5:00:00 PM -Total : 1 -Cached : 1 -Blocked : 0 -Forwarded : 0 +Timestamp : 10/12/2026 5:20:00 PM +Total : 256 +Cached : 136 +Blocked : 90 +Forwarded : 30 -Timestamp : 10/6/2026 6:00:00 PM -Total : 1 -Cached : 1 +Timestamp : 10/12/2026 5:30:00 PM +Total : 4 +Cached : 2 Blocked : 0 -Forwarded : 0 - -Timestamp : 10/6/2026 7:00:00 PM -Total : 1 -Cached : 1 -Blocked : 0 -Forwarded : 0 - -_(showing 5 of 10 results)_ +Forwarded : 2 ``` ### Get-PiHoleHistoryDatabaseClient @@ -1386,22 +1415,14 @@ Get-PiHoleHistoryDatabaseClient -PiHoleServer $PiHoleServer -Password $Password ``` -Timestamp : 10/6/2026 10:00:00 PM -Clients : {@{ClientId=5; Count=1}, @{ClientId=3; Count=1}} - -Timestamp : 10/6/2026 9:50:00 PM -Clients : @{ClientId=3; Count=1} - -Timestamp : 10/6/2026 9:40:00 PM +Timestamp : 10/12/2026 5:30:00 PM Clients : @{ClientId=3; Count=1} -Timestamp : 10/6/2026 9:00:00 PM -Clients : @{ClientId=3; Count=1} - -Timestamp : 10/6/2026 8:00:00 PM -Clients : @{ClientId=3; Count=1} +Timestamp : 10/12/2026 5:20:00 PM +Clients : {@{ClientId=3; Count=1}, @{ClientId=5; Count=1}} -_(showing 5 of 10 results)_ +Timestamp : 10/12/2026 5:10:00 PM +Clients : {@{ClientId=3; Count=1}, @{ClientId=2; Count=1}, @{ClientId=5; Count=1}} ``` ### Get-PiHoleNetworkGateway @@ -1497,7 +1518,7 @@ ProtoDown : False Address : 00:00:00:00:00:00 Broadcast : 00:00:00:00:00:00 Stats : @{RxBytes=; TxBytes=; Bits=64} -Addresses : {@{Family=inet; Scope=host; Flags=permanent; Prefixlen=8; Address=127.0.0.1; AddressType=loopback; Local=127.0.0.1; LocalType=loopback; Label=lo; Prefered=4294967295; Valid=4294967295; Cstamp=1790957600.02; Tstamp=1790957600.02}, @{Family=inet6; Scope=host; Flags=permanent; Prefixlen=128; Address=::1; AddressType=loopback; Prefered=4294967295; Valid=4294967295; Cstamp=1790957600.02; Tstamp=1790957600.02}} +Addresses : {@{Family=inet; Scope=host; Flags=permanent; Prefixlen=8; Address=127.0.0.1; AddressType=loopback; Local=127.0.0.1; LocalType=loopback; Label=lo; Prefered=4294967295; Valid=4294967295; Cstamp=1791692111.02; Tstamp=1791692111.02}, @{Family=inet6; Scope=host; Flags=permanent; Prefixlen=128; Address=::1; AddressType=loopback; Prefered=4294967295; Valid=4294967295; Cstamp=1791692111.02; Tstamp=1791692111.02}} Name : wlan0 Speed : @@ -1510,7 +1531,7 @@ Address : b8:27:eb:11:a4:d5 Broadcast : ff:ff:ff:ff:ff:ff PermAddress : b8:27:eb:11:a4:d5 Stats : @{RxBytes=; TxBytes=; Bits=64} -Addresses : {@{Family=inet; Scope=universe; Flags=; Prefixlen=24; Address=192.168.1.248; AddressType=private; Local=192.168.1.248; LocalType=private; Broadcast=192.168.1.255; BroadcastType=private; Label=wlan0; Prefered=62449; Valid=62449; Cstamp=1790957620.44; Tstamp=1791318773.93}, @{Family=inet6; Scope=link; Flags=permanent; Prefixlen=64; Address=fe80::ba27:ebff:fe11:a4d5; AddressType=link-local (LL); Prefered=4294967295; Valid=4294967295; Cstamp=1790957619.8; Tstamp=1790957619.8}} +Addresses : {@{Family=inet; Scope=universe; Flags=; Prefixlen=24; Address=192.168.1.248; AddressType=private; Local=192.168.1.248; LocalType=private; Broadcast=192.168.1.255; BroadcastType=private; Label=wlan0; Prefered=74660; Valid=74660; Cstamp=1791692137.78; Tstamp=1791833219.34}, @{Family=inet6; Scope=link; Flags=permanent; Prefixlen=64; Address=fe80::ba27:ebff:fe11:a4d5; AddressType=link-local (LL); Prefered=4294967295; Valid=4294967295; Cstamp=1791692130.87; Tstamp=1791692130.87}} ``` ### Get-PiHoleNetworkDevice @@ -1526,20 +1547,20 @@ Get-PiHoleNetworkDevice -PiHoleServer $PiHoleServer -Password $Password Id : 2 HwAddr : ip-127.0.0.1 Interface : lo -FirstSeen : 10/4/2026 2:31:10 PM -LastQuery : 10/6/2026 10:06:14 PM -NumQueries : 82 +FirstSeen : 10/12/2026 5:12:02 PM +LastQuery : 10/12/2026 5:36:48 PM +NumQueries : 24 MacVendor : -Ips : @{Ip=127.0.0.1; Name=localhost; LastSeen=10/6/2026 10:12:00 PM; NameUpdated=10/6/2026 10:12:00 PM} +Ips : @{Ip=127.0.0.1; Name=localhost; LastSeen=10/12/2026 5:42:00 PM; NameUpdated=10/12/2026 5:42:00 PM} Id : 1 HwAddr : 74:56:3c:bb:f4:0b Interface : wlan0 -FirstSeen : 10/4/2026 2:31:09 PM -LastQuery : 10/6/2026 10:03:16 PM -NumQueries : 318 +FirstSeen : 10/12/2026 5:12:01 PM +LastQuery : 10/12/2026 5:27:24 PM +NumQueries : 268 MacVendor : Giga-Byte Technology Co.,Ltd. -Ips : @{Ip=192.168.1.162; Name=; LastSeen=10/6/2026 10:12:00 PM; NameUpdated=12/31/1969 6:00:00 PM} +Ips : @{Ip=192.168.1.162; Name=; LastSeen=10/12/2026 5:42:00 PM; NameUpdated=12/31/1969 6:00:00 PM} ``` ### Remove-PiHoleNetworkDevice @@ -1592,8 +1613,8 @@ Get-PiHoleAuthStatus -PiHoleServer $PiHoleServer -Password $Password Valid : True Totp : False -Sid : +dfslUHafhrdo0TwRT5nxQ= -Csrf : Em6pqkbJ6cuWxjQw7EtUFw= +Sid : hC4IO7uXkDyqfnkruxSkQw= +Csrf : kW1Eb243nJQ7vpBky2AX3A= Validity : 1800 Message : correct password ``` @@ -1613,8 +1634,8 @@ Algorithm : SHA1 Digits : 6 Period : 30 Offset : 0 -Secret : EG7DLOTZKTQWIRWBFR2JJLS5Q3BYNUN3 -Codes : {201435, 619358, 736784, 226002…} +Secret : P4HHFM7JOMC7N4XN7ACW2FITOZBYNOR3 +Codes : {630810, 93752, 414226, 216678…} ``` ### Get-PiHoleCurrentAuthSession @@ -1630,9 +1651,9 @@ CurrentSession : False Valid : True TlsLogin : True TlsMixed : False -LoginAt : 10/6/2026 9:44:13 PM -LastActive : 10/6/2026 9:44:17 PM -ValidUntil : 10/6/2026 10:14:17 PM +LoginAt : 10/12/2026 5:26:22 PM +LastActive : 10/12/2026 5:26:22 PM +ValidUntil : 10/12/2026 5:56:22 PM RemoteAddress : 192.168.1.162 UserAgent : Mozilla/5.0 (Windows NT 10.0; Microsoft Windows 10.0.26200; en-US) PowerShell/7.6.6 XForwardedFor : @@ -1644,9 +1665,9 @@ CurrentSession : False Valid : True TlsLogin : True TlsMixed : False -LoginAt : 10/6/2026 9:44:59 PM -LastActive : 10/6/2026 9:44:59 PM -ValidUntil : 10/6/2026 10:14:59 PM +LoginAt : 10/12/2026 5:27:32 PM +LastActive : 10/12/2026 5:27:41 PM +ValidUntil : 10/12/2026 5:57:41 PM RemoteAddress : 192.168.1.162 UserAgent : Mozilla/5.0 (Windows NT 10.0; Microsoft Windows 10.0.26200; en-US) PowerShell/7.6.6 XForwardedFor : @@ -1658,9 +1679,9 @@ CurrentSession : True Valid : True TlsLogin : True TlsMixed : False -LoginAt : 10/6/2026 10:03:33 PM -LastActive : 10/6/2026 10:03:37 PM -ValidUntil : 10/6/2026 10:33:37 PM +LoginAt : 10/12/2026 5:33:50 PM +LastActive : 10/12/2026 5:33:55 PM +ValidUntil : 10/12/2026 6:03:55 PM RemoteAddress : 192.168.1.162 UserAgent : Mozilla/5.0 (Windows NT 10.0; Microsoft Windows 10.0.26200; en-US) PowerShell/7.6.6 XForwardedFor : diff --git a/tests/DnsControl/Add-PiHoleDnsRecord.Integration.Tests.ps1 b/tests/DnsControl/Add-PiHoleDnsRecord.Integration.Tests.ps1 new file mode 100644 index 0000000..a1a26d1 --- /dev/null +++ b/tests/DnsControl/Add-PiHoleDnsRecord.Integration.Tests.ps1 @@ -0,0 +1,111 @@ +# Requires -Module Pester +# +# Integration tests that call a REAL Pi-hole server. Configure tests/IntegrationConfig.local.ps1 +# (copy it from IntegrationConfig.example.ps1) before running. Tests are skipped automatically +# if that file is missing. +# +# NOTE: these tests add/remove fake records using TEST-NET-1/documentation (RFC 5737/3849) +# reserved addresses that will never route anywhere real. They require the app password used +# here to have "app_sudo" enabled in Pi-hole (Settings > All Settings), same as +# Add-PiHoleConfigArrayItem (called internally) - see its .DESCRIPTION. -Restart $false is used +# throughout to avoid the brief FTL restart a real config change otherwise triggers. + +$script:ConfigAvailable = Test-Path (Join-Path (Split-Path $PSScriptRoot -Parent) 'IntegrationConfig.local.ps1') + +Describe 'Add-PiHoleDnsRecord (Integration)' -Tag 'Integration' { + BeforeAll { + Import-Module .\PiHoleShell\PiHoleShell.psm1 -Force + + $script:AHostname = 'piholeshell-test-a.example.com' + $script:AIPv4 = '192.0.2.201' + $script:AaaaHostname = 'piholeshell-test-aaaa.example.com' + $script:AaaaIPv6 = '2001:db8::201' + $script:CnameHostname = 'piholeshell-test-cname.example.com' + $script:CnameTarget = 'piholeshell-test-a.example.com' + $script:CnameTtl = 300 + + $configPath = Join-Path (Split-Path $PSScriptRoot -Parent) 'IntegrationConfig.local.ps1' + if (Test-Path $configPath) { + . $configPath + $script:PiHoleServer = $PiHoleServer + $script:PiHoleToken = $PiHoleToken + $script:PiHoleIgnoreSsl = $PiHoleIgnoreSsl + + # Defensive cleanup in case a previous failed run left these behind + Remove-PiHoleConfigArrayItem -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Element 'dns/hosts' -Value "$script:AIPv4 $script:AHostname" -Restart $false -Confirm:$false -ErrorAction SilentlyContinue -WarningAction SilentlyContinue | Out-Null + Remove-PiHoleConfigArrayItem -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Element 'dns/hosts' -Value "$script:AaaaIPv6 $script:AaaaHostname" -Restart $false -Confirm:$false -ErrorAction SilentlyContinue -WarningAction SilentlyContinue | Out-Null + Remove-PiHoleConfigArrayItem -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Element 'dns/cnameRecords' -Value "$script:CnameHostname,$script:CnameTarget,$script:CnameTtl" -Restart $false -Confirm:$false -ErrorAction SilentlyContinue -WarningAction SilentlyContinue | Out-Null + } + } + + AfterAll { + if ($script:PiHoleServer) { + Remove-PiHoleConfigArrayItem -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Element 'dns/hosts' -Value "$script:AIPv4 $script:AHostname" -Restart $false -Confirm:$false -ErrorAction SilentlyContinue | Out-Null + Remove-PiHoleConfigArrayItem -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Element 'dns/hosts' -Value "$script:AaaaIPv6 $script:AaaaHostname" -Restart $false -Confirm:$false -ErrorAction SilentlyContinue | Out-Null + Remove-PiHoleConfigArrayItem -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Element 'dns/cnameRecords' -Value "$script:CnameHostname,$script:CnameTarget,$script:CnameTtl" -Restart $false -Confirm:$false -ErrorAction SilentlyContinue | Out-Null + } + } + + It 'adds an A record and returns a formatted object' -Skip:(-not $script:ConfigAvailable) { + $result = Add-PiHoleDnsRecord -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Type A -Hostname $script:AHostname -IPv4Address $script:AIPv4 -Restart $false + $result | Format-List | Out-String | Write-Host + + $result | Should -Not -BeNullOrEmpty + $result.Status | Should -Be 'Added' + + $hosts = (Get-PiHoleConfig -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl).Dns.Hosts + $hosts | Should -Contain "$script:AIPv4 $script:AHostname" + + Remove-PiHoleConfigArrayItem -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Element 'dns/hosts' -Value "$script:AIPv4 $script:AHostname" -Restart $false -Confirm:$false | Out-Null + } + + It 'adds an AAAA record and returns a formatted object' -Skip:(-not $script:ConfigAvailable) { + $result = Add-PiHoleDnsRecord -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Type AAAA -Hostname $script:AaaaHostname -IPv6Address $script:AaaaIPv6 -Restart $false + $result | Format-List | Out-String | Write-Host + + $result | Should -Not -BeNullOrEmpty + $result.Status | Should -Be 'Added' + + $hosts = (Get-PiHoleConfig -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl).Dns.Hosts + $hosts | Should -Contain "$script:AaaaIPv6 $script:AaaaHostname" + + Remove-PiHoleConfigArrayItem -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Element 'dns/hosts' -Value "$script:AaaaIPv6 $script:AaaaHostname" -Restart $false -Confirm:$false | Out-Null + } + + It 'adds a CNAME record with a TTL and returns a formatted object' -Skip:(-not $script:ConfigAvailable) { + $result = Add-PiHoleDnsRecord -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Type CNAME -Hostname $script:CnameHostname -Target $script:CnameTarget -Ttl $script:CnameTtl -Restart $false + $result | Format-List | Out-String | Write-Host + + $result | Should -Not -BeNullOrEmpty + $result.Status | Should -Be 'Added' + + $cnames = (Get-PiHoleConfig -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl).Dns.CnameRecords + $cnames | Should -Contain "$script:CnameHostname,$script:CnameTarget,$script:CnameTtl" + + Remove-PiHoleConfigArrayItem -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Element 'dns/cnameRecords' -Value "$script:CnameHostname,$script:CnameTarget,$script:CnameTtl" -Restart $false -Confirm:$false | Out-Null + } + + It 'errors when -IPv4Address is missing for -Type A' -Skip:(-not $script:ConfigAvailable) { + $result = Add-PiHoleDnsRecord -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Type A -Hostname $script:AHostname -Restart $false -ErrorVariable errOut -ErrorAction SilentlyContinue + + $errOut | Should -Not -BeNullOrEmpty + } + + It 'errors when -IPv4Address is not a valid IPv4 address' -Skip:(-not $script:ConfigAvailable) { + $result = Add-PiHoleDnsRecord -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Type A -Hostname $script:AHostname -IPv4Address '2001:db8::1' -Restart $false -ErrorVariable errOut -ErrorAction SilentlyContinue + + $errOut | Should -Not -BeNullOrEmpty + } + + It 'errors when -Target is missing for -Type CNAME' -Skip:(-not $script:ConfigAvailable) { + $result = Add-PiHoleDnsRecord -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Type CNAME -Hostname $script:CnameHostname -Restart $false -ErrorVariable errOut -ErrorAction SilentlyContinue + + $errOut | Should -Not -BeNullOrEmpty + } + + It 'errors when given a bad password' -Skip:(-not $script:ConfigAvailable) { + $result = Add-PiHoleDnsRecord -PiHoleServer $script:PiHoleServer -Password 'definitely-not-the-real-token' -IgnoreSsl $script:PiHoleIgnoreSsl -Type A -Hostname $script:AHostname -IPv4Address $script:AIPv4 -Restart $false -ErrorVariable errOut -ErrorAction SilentlyContinue + + $errOut | Should -Not -BeNullOrEmpty + } +} diff --git a/tests/DnsControl/Remove-PiHoleDnsRecord.Integration.Tests.ps1 b/tests/DnsControl/Remove-PiHoleDnsRecord.Integration.Tests.ps1 new file mode 100644 index 0000000..e8b9a0e --- /dev/null +++ b/tests/DnsControl/Remove-PiHoleDnsRecord.Integration.Tests.ps1 @@ -0,0 +1,85 @@ +# Requires -Module Pester +# +# Integration tests that call a REAL Pi-hole server. Configure tests/IntegrationConfig.local.ps1 +# (copy it from IntegrationConfig.example.ps1) before running. Tests are skipped automatically +# if that file is missing. +# +# NOTE: these tests add/remove fake records using TEST-NET-1/documentation (RFC 5737/3849) +# reserved addresses that will never route anywhere real. -Restart $false is used throughout to +# avoid the brief FTL restart a real config change otherwise triggers. + +$script:ConfigAvailable = Test-Path (Join-Path (Split-Path $PSScriptRoot -Parent) 'IntegrationConfig.local.ps1') + +Describe 'Remove-PiHoleDnsRecord (Integration)' -Tag 'Integration' { + BeforeAll { + Import-Module .\PiHoleShell\PiHoleShell.psm1 -Force + + $script:AHostname = 'piholeshell-test-remove-a.example.com' + $script:AIPv4 = '192.0.2.202' + $script:CnameHostname = 'piholeshell-test-remove-cname.example.com' + $script:CnameTarget = 'piholeshell-test-remove-a.example.com' + $script:CnameTtl = 300 + + $configPath = Join-Path (Split-Path $PSScriptRoot -Parent) 'IntegrationConfig.local.ps1' + if (Test-Path $configPath) { + . $configPath + $script:PiHoleServer = $PiHoleServer + $script:PiHoleToken = $PiHoleToken + $script:PiHoleIgnoreSsl = $PiHoleIgnoreSsl + + # Defensive cleanup in case a previous failed run left these behind + Remove-PiHoleConfigArrayItem -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Element 'dns/hosts' -Value "$script:AIPv4 $script:AHostname" -Restart $false -Confirm:$false -ErrorAction SilentlyContinue -WarningAction SilentlyContinue | Out-Null + Remove-PiHoleConfigArrayItem -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Element 'dns/cnameRecords' -Value "$script:CnameHostname,$script:CnameTarget,$script:CnameTtl" -Restart $false -Confirm:$false -ErrorAction SilentlyContinue -WarningAction SilentlyContinue | Out-Null + } + } + + AfterAll { + if ($script:PiHoleServer) { + Remove-PiHoleConfigArrayItem -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Element 'dns/hosts' -Value "$script:AIPv4 $script:AHostname" -Restart $false -Confirm:$false -ErrorAction SilentlyContinue | Out-Null + Remove-PiHoleConfigArrayItem -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Element 'dns/cnameRecords' -Value "$script:CnameHostname,$script:CnameTarget,$script:CnameTtl" -Restart $false -Confirm:$false -ErrorAction SilentlyContinue | Out-Null + } + } + + It 'removes an A record and returns a formatted object' -Skip:(-not $script:ConfigAvailable) { + Add-PiHoleConfigArrayItem -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Element 'dns/hosts' -Value "$script:AIPv4 $script:AHostname" -Restart $false | Out-Null + + $result = Remove-PiHoleDnsRecord -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Type A -Hostname $script:AHostname -IPv4Address $script:AIPv4 -Restart $false -Confirm:$false + $result | Format-List | Out-String | Write-Host + + $result | Should -Not -BeNullOrEmpty + $result.Status | Should -Be 'Removed' + + $hosts = (Get-PiHoleConfig -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl).Dns.Hosts + $hosts | Should -Not -Contain "$script:AIPv4 $script:AHostname" + } + + It 'removes a CNAME record with a matching TTL' -Skip:(-not $script:ConfigAvailable) { + Add-PiHoleConfigArrayItem -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Element 'dns/cnameRecords' -Value "$script:CnameHostname,$script:CnameTarget,$script:CnameTtl" -Restart $false | Out-Null + + $result = Remove-PiHoleDnsRecord -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Type CNAME -Hostname $script:CnameHostname -Target $script:CnameTarget -Ttl $script:CnameTtl -Restart $false -Confirm:$false + $result | Format-List | Out-String | Write-Host + + $result | Should -Not -BeNullOrEmpty + $result.Status | Should -Be 'Removed' + + $cnames = (Get-PiHoleConfig -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl).Dns.CnameRecords + $cnames | Should -Not -Contain "$script:CnameHostname,$script:CnameTarget,$script:CnameTtl" + } + + It 'does not remove anything when -WhatIf is set' -Skip:(-not $script:ConfigAvailable) { + Add-PiHoleConfigArrayItem -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Element 'dns/hosts' -Value "$script:AIPv4 $script:AHostname" -Restart $false | Out-Null + + Remove-PiHoleDnsRecord -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Type A -Hostname $script:AHostname -IPv4Address $script:AIPv4 -Restart $false -WhatIf + + $hosts = (Get-PiHoleConfig -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl).Dns.Hosts + $hosts | Should -Contain "$script:AIPv4 $script:AHostname" + + Remove-PiHoleConfigArrayItem -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Element 'dns/hosts' -Value "$script:AIPv4 $script:AHostname" -Restart $false -Confirm:$false | Out-Null + } + + It 'errors when given a bad password' -Skip:(-not $script:ConfigAvailable) { + $result = Remove-PiHoleDnsRecord -PiHoleServer $script:PiHoleServer -Password 'definitely-not-the-real-token' -IgnoreSsl $script:PiHoleIgnoreSsl -Type A -Hostname $script:AHostname -IPv4Address $script:AIPv4 -Restart $false -Confirm:$false -ErrorVariable errOut -ErrorAction SilentlyContinue + + $errOut | Should -Not -BeNullOrEmpty + } +} diff --git a/tools/Update-ExampleOutput.ps1 b/tools/Update-ExampleOutput.ps1 index 35cb802..3107407 100644 --- a/tools/Update-ExampleOutput.ps1 +++ b/tools/Update-ExampleOutput.ps1 @@ -193,6 +193,17 @@ if ($appSudoEnabled) { Add-Example -Category Config -FunctionName 'Remove-PiHoleConfigArrayItem' ` -Invocation "Remove-PiHoleConfigArrayItem -PiHoleServer `$PiHoleServer -Password `$Password -Element `"dns/hosts`" -Value `"$docsHostEntry`"" ` -Result (Remove-PiHoleConfigArrayItem -PiHoleServer $PiHoleServer -Password $PiHoleToken -IgnoreSsl $PiHoleIgnoreSsl -Element 'dns/hosts' -Value $docsHostEntry -Restart $false -Confirm:$false) + + $docsDnsHostname = 'piholeshell-docs-dns-example.com' + Invoke-Quietly { Remove-PiHoleConfigArrayItem -PiHoleServer $PiHoleServer -Password $PiHoleToken -IgnoreSsl $PiHoleIgnoreSsl -Element 'dns/hosts' -Value "192.0.2.2 $docsDnsHostname" -Restart $false -Confirm:$false } + + Add-Example -Category DnsControl -FunctionName 'Add-PiHoleDnsRecord' ` + -Invocation "Add-PiHoleDnsRecord -PiHoleServer `$PiHoleServer -Password `$Password -Type A -Hostname `"$docsDnsHostname`" -IPv4Address `"192.0.2.2`"" ` + -Result (Add-PiHoleDnsRecord -PiHoleServer $PiHoleServer -Password $PiHoleToken -IgnoreSsl $PiHoleIgnoreSsl -Type A -Hostname $docsDnsHostname -IPv4Address '192.0.2.2' -Restart $false) + + Add-Example -Category DnsControl -FunctionName 'Remove-PiHoleDnsRecord' ` + -Invocation "Remove-PiHoleDnsRecord -PiHoleServer `$PiHoleServer -Password `$Password -Type A -Hostname `"$docsDnsHostname`" -IPv4Address `"192.0.2.2`"" ` + -Result (Remove-PiHoleDnsRecord -PiHoleServer $PiHoleServer -Password $PiHoleToken -IgnoreSsl $PiHoleIgnoreSsl -Type A -Hostname $docsDnsHostname -IPv4Address '192.0.2.2' -Restart $false -Confirm:$false) } else { $appSudoNote = 'Requires "app_sudo" enabled for this app password (Settings > All Settings in your Pi-hole admin UI) - not captured this run since it is disabled here.' @@ -205,6 +216,12 @@ else { Add-Example -Category Config -FunctionName 'Remove-PiHoleConfigArrayItem' ` -Invocation 'Remove-PiHoleConfigArrayItem -PiHoleServer $PiHoleServer -Password $Password -Element "dns/hosts" -Value "192.0.2.1 example.com"' ` -Note $appSudoNote -Skipped + Add-Example -Category DnsControl -FunctionName 'Add-PiHoleDnsRecord' ` + -Invocation 'Add-PiHoleDnsRecord -PiHoleServer $PiHoleServer -Password $Password -Type A -Hostname "example.com" -IPv4Address "192.0.2.1"' ` + -Note $appSudoNote -Skipped + Add-Example -Category DnsControl -FunctionName 'Remove-PiHoleDnsRecord' ` + -Invocation 'Remove-PiHoleDnsRecord -PiHoleServer $PiHoleServer -Password $Password -Type A -Hostname "example.com" -IPv4Address "192.0.2.1"' ` + -Note $appSudoNote -Skipped } Add-Example -Category Config -FunctionName 'Get-PiHolePadd' ` From d8a68f1cb7d6ebee56e549e8213c8722d58ef95a Mon Sep 17 00:00:00 2001 From: Mike Madeja Date: Mon, 12 Oct 2026 18:50:17 -0500 Subject: [PATCH 3/7] feat: add Get-PiHoleDnsRecord, with pipeline support into Remove Adds Get-PiHoleDnsRecord, completing the Get/Add/Remove set for local DNS record management. Parses Pi-hole's raw dns.hosts/dns.cnameRecords config arrays into the same typed object shape Add-/Remove-PiHoleDnsRecord already use (Type/Hostname/IPv4Address/IPv6Address/Target/Ttl), with optional -Type/-Hostname filtering. Remove-PiHoleDnsRecord now accepts that same shape via ValueFromPipelineByPropertyName, so Get-PiHoleDnsRecord's output can be piped straight into it - including removing several matched records in a single pipeline. This is the first use of pipeline input anywhere in the module; no other function currently has a matching Get/Remove object shape to make it worthwhile. Co-Authored-By: Claude Sonnet 5 --- PiHoleShell/PiHoleShell.psd1 | Bin 7042 -> 7088 bytes PiHoleShell/PiHoleShell.psm1 | 2 +- .../Public/DnsControl/Get-PiHoleDnsRecord.ps1 | 113 +++++ .../DnsControl/Remove-PiHoleDnsRecord.ps1 | 127 +++--- README.md | 1 + docs/EXAMPLES.md | 402 +++++++++--------- .../Get-PiHoleDnsRecord.Integration.Tests.ps1 | 106 +++++ ...move-PiHoleDnsRecord.Integration.Tests.ps1 | 17 + tools/Update-ExampleOutput.ps1 | 8 + 9 files changed, 523 insertions(+), 253 deletions(-) create mode 100644 PiHoleShell/Public/DnsControl/Get-PiHoleDnsRecord.ps1 create mode 100644 tests/DnsControl/Get-PiHoleDnsRecord.Integration.Tests.ps1 diff --git a/PiHoleShell/PiHoleShell.psd1 b/PiHoleShell/PiHoleShell.psd1 index 296da85e69495fb923cfb6cfca96504b37a8e652..bc9c9cb18c8d905d9ba2565b1df26aac550abafb 100644 GIT binary patch delta 130 zcmZoN-(bFB0{dh=cCpD~+yRq6u!}GTPj2KF2C}>+S8>=(4iJ=@Jb|5OvI>XPc*3!v(#$p)NqlPlOICKvEeRNC22E!6h{L8>iCb2b^q^ TyST!@`k1&yKw_H4x7mdTp)3t$t;`} zlPlOICO_cfnmmnDZZaEB)Z|w{_5)6r$!$DJlk2#Iz+!w{Y?F6zg@MH~xJ965$W2b* L5!k$rn@IowDfT5# diff --git a/PiHoleShell/PiHoleShell.psm1 b/PiHoleShell/PiHoleShell.psm1 index 41ec551..d73e2ab 100644 --- a/PiHoleShell/PiHoleShell.psm1 +++ b/PiHoleShell/PiHoleShell.psm1 @@ -22,7 +22,7 @@ Export-ModuleMember -Function @( #GroupManagement 'Get-PiHoleGroup', 'New-PiHoleGroup', 'Update-PiHoleGroup', 'Remove-PiHoleGroup', ` #DnsControl - 'Get-PiHoleDnsBlockingStatus', 'Set-PiHoleDnsBlocking', 'Add-PiHoleDnsRecord', 'Remove-PiHoleDnsRecord', ` + 'Get-PiHoleDnsBlockingStatus', 'Set-PiHoleDnsBlocking', 'Add-PiHoleDnsRecord', 'Remove-PiHoleDnsRecord', 'Get-PiHoleDnsRecord', ` #Config 'Get-PiHoleConfig', 'Set-PiHoleConfig', 'Add-PiHoleConfigArrayItem', 'Remove-PiHoleConfigArrayItem', 'Get-PiHoleConfigProperty', ` #Padd diff --git a/PiHoleShell/Public/DnsControl/Get-PiHoleDnsRecord.ps1 b/PiHoleShell/Public/DnsControl/Get-PiHoleDnsRecord.ps1 new file mode 100644 index 0000000..0b98a36 --- /dev/null +++ b/PiHoleShell/Public/DnsControl/Get-PiHoleDnsRecord.ps1 @@ -0,0 +1,113 @@ +function Get-PiHoleDnsRecord { + <# +.SYNOPSIS +Get local DNS records + +.DESCRIPTION +Returns Pi-hole's local DNS records (A, AAAA, and CNAME) as a flat list of objects shaped the +same way as Add-PiHoleDnsRecord/Remove-PiHoleDnsRecord, so the result can be piped straight into +Remove-PiHoleDnsRecord. This is a DNS-specific convenience wrapper around Get-PiHoleConfig, +which it calls internally - using that directly (.Dns.Hosts / .Dns.CnameRecords) is equivalent, +just not already split into A/AAAA/CNAME or filterable by -Type/-Hostname. + +.PARAMETER PiHoleServer +The URL to the PiHole Server, for example "http://pihole.domain.com:8080", or "http://192.168.1.100" + +.PARAMETER Password +The API Password you generated from your PiHole server + +.PARAMETER Type +Only return records of this kind: A (IPv4), AAAA (IPv6), or CNAME. If omitted, all are returned + +.PARAMETER Hostname +Only return the record(s) for this exact hostname (the alias, for a CNAME). If omitted, every +record is returned + +.PARAMETER IgnoreSsl +Set to $true to skip SSL certificate validation + +.PARAMETER RawOutput +This will dump the response instead of the formatted object + +.EXAMPLE +Get-PiHoleDnsRecord -PiHoleServer "http://pihole.domain.com:8080" -Password "your-app-password" + +.EXAMPLE +Get-PiHoleDnsRecord -PiHoleServer "http://pihole.domain.com:8080" -Password "your-app-password" -Type CNAME + +.EXAMPLE +Get-PiHoleDnsRecord -PiHoleServer "http://pihole.domain.com:8080" -Password "your-app-password" -Hostname "test.local" | Remove-PiHoleDnsRecord -PiHoleServer "http://pihole.domain.com:8080" -Password "your-app-password" + #> + [CmdletBinding(HelpUri = 'https://ftl.pi-hole.net/master/docs/#get-/config')] + [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingPlainTextForPassword", "Password")] + param ( + [Parameter(Mandatory = $true)] + [System.URI]$PiHoleServer, + [Parameter(Mandatory = $true)] + [string]$Password, + [ValidateSet('A', 'AAAA', 'CNAME')] + [string]$Type, + [string]$Hostname, + [bool]$IgnoreSsl = $false, + [bool]$RawOutput = $false + ) + try { + $Config = Get-PiHoleConfig -PiHoleServer $PiHoleServer -Password $Password -IgnoreSsl $IgnoreSsl -ErrorAction Stop + + if ($RawOutput) { + $Object = [PSCustomObject]@{ + Hosts = $Config.Dns.Hosts + CnameRecords = $Config.Dns.CnameRecords + } + Write-Output $Object + } + else { + $Records = foreach ($Entry in $Config.Dns.Hosts) { + # Each entry is " " - hostnames never contain spaces, so splitting + # into at most 2 parts on the first space is safe even if an IPv6 address itself + # cannot contain one. + $Parts = $Entry.Split(' ', 2) + $Address = $Parts[0] + $RecordHostname = $Parts[1] + + $ParsedAddress = $null + $IsIPv6 = [System.Net.IPAddress]::TryParse($Address, [ref]$ParsedAddress) -and $ParsedAddress.AddressFamily -eq [System.Net.Sockets.AddressFamily]::InterNetworkV6 + + [PSCustomObject]@{ + Type = if ($IsIPv6) { 'AAAA' } else { 'A' } + Hostname = $RecordHostname + IPv4Address = if ($IsIPv6) { $null } else { $Address } + IPv6Address = if ($IsIPv6) { $Address } else { $null } + Target = $null + Ttl = $null + } + } + + $Records += foreach ($Entry in $Config.Dns.CnameRecords) { + # Each entry is ",[,]" - the TTL segment is optional. + $Parts = $Entry.Split(',') + [PSCustomObject]@{ + Type = 'CNAME' + Hostname = $Parts[0] + IPv4Address = $null + IPv6Address = $null + Target = $Parts[1] + Ttl = if ($Parts.Count -gt 2) { [int]$Parts[2] } else { $null } + } + } + + if ($PSBoundParameters.ContainsKey('Type')) { + $Records = $Records | Where-Object { $_.Type -eq $Type } + } + if ($PSBoundParameters.ContainsKey('Hostname')) { + $Records = $Records | Where-Object { $_.Hostname -eq $Hostname } + } + + Write-Output $Records + } + } + + catch { + Write-Error -Message $_.Exception.Message + } +} diff --git a/PiHoleShell/Public/DnsControl/Remove-PiHoleDnsRecord.ps1 b/PiHoleShell/Public/DnsControl/Remove-PiHoleDnsRecord.ps1 index bb2cf0b..e031278 100644 --- a/PiHoleShell/Public/DnsControl/Remove-PiHoleDnsRecord.ps1 +++ b/PiHoleShell/Public/DnsControl/Remove-PiHoleDnsRecord.ps1 @@ -9,9 +9,11 @@ record. This is a DNS-specific convenience wrapper around Remove-PiHoleConfigArr it calls internally - using that directly is equivalent, just less discoverable for this specific case. -The values given must match the record exactly as it was created (see Get-PiHoleConfig, -under .Dns.Hosts or .Dns.CnameRecords, to check the exact value if removal fails) - for a CNAME -record created with a TTL, -Ttl must be passed here too, with the same value. +The values given must match the record exactly as it was created (see Get-PiHoleDnsRecord, or +Get-PiHoleConfig under .Dns.Hosts/.Dns.CnameRecords, to check the exact value if removal fails) - +for a CNAME record created with a TTL, -Ttl must be passed here too, with the same value. + +Accepts pipeline input by property name, so it can be chained directly from Get-PiHoleDnsRecord. .PARAMETER PiHoleServer The URL to the PiHole Server, for example "http://pihole.domain.com:8080", or "http://192.168.1.100" @@ -55,6 +57,9 @@ Remove-PiHoleDnsRecord -PiHoleServer "http://pihole.domain.com:8080" -Password " .EXAMPLE Remove-PiHoleDnsRecord -PiHoleServer "http://pihole.domain.com:8080" -Password "your-app-password" -Type CNAME -Hostname "alias.local" -Target "test.local" -Ttl 300 + +.EXAMPLE +Get-PiHoleDnsRecord -PiHoleServer "http://pihole.domain.com:8080" -Password "your-app-password" -Hostname "test.local" | Remove-PiHoleDnsRecord -PiHoleServer "http://pihole.domain.com:8080" -Password "your-app-password" #> [CmdletBinding(SupportsShouldProcess = $true, HelpUri = 'https://ftl.pi-hole.net/master/docs/#delete-/config/-element-/-value-')] [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingPlainTextForPassword", "Password")] @@ -63,82 +68,88 @@ Remove-PiHoleDnsRecord -PiHoleServer "http://pihole.domain.com:8080" -Password " [System.URI]$PiHoleServer, [Parameter(Mandatory = $true)] [string]$Password, - [Parameter(Mandatory = $true)] + [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)] [ValidateSet('A', 'AAAA', 'CNAME')] [string]$Type, - [Parameter(Mandatory = $true)] + [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)] [string]$Hostname, + [Parameter(ValueFromPipelineByPropertyName = $true)] [string]$IPv4Address, + [Parameter(ValueFromPipelineByPropertyName = $true)] [string]$IPv6Address, + [Parameter(ValueFromPipelineByPropertyName = $true)] [string]$Target, + [Parameter(ValueFromPipelineByPropertyName = $true)] [Nullable[int]]$Ttl, [Nullable[bool]]$Restart, [bool]$IgnoreSsl = $false, [bool]$RawOutput = $false ) - try { - switch ($Type) { - 'A' { - if (-not $IPv4Address) { - throw "-IPv4Address is required when -Type is 'A'" + process { + try { + switch ($Type) { + 'A' { + if (-not $IPv4Address) { + throw "-IPv4Address is required when -Type is 'A'" + } + $Element = 'dns/hosts' + $Value = "$IPv4Address $Hostname" } - $Element = 'dns/hosts' - $Value = "$IPv4Address $Hostname" - } - 'AAAA' { - if (-not $IPv6Address) { - throw "-IPv6Address is required when -Type is 'AAAA'" - } - $Element = 'dns/hosts' - $Value = "$IPv6Address $Hostname" - } - 'CNAME' { - if (-not $Target) { - throw "-Target is required when -Type is 'CNAME'" + 'AAAA' { + if (-not $IPv6Address) { + throw "-IPv6Address is required when -Type is 'AAAA'" + } + $Element = 'dns/hosts' + $Value = "$IPv6Address $Hostname" } - $Element = 'dns/cnameRecords' - $Value = "$Hostname,$Target" - if ($PSBoundParameters.ContainsKey('Ttl')) { - $Value += ",$Ttl" + 'CNAME' { + if (-not $Target) { + throw "-Target is required when -Type is 'CNAME'" + } + $Element = 'dns/cnameRecords' + $Value = "$Hostname,$Target" + if ($PSBoundParameters.ContainsKey('Ttl')) { + $Value += ",$Ttl" + } } } - } - if ($PSCmdlet.ShouldProcess("Pi-Hole DNS record '$Value' ($Type)", "Remove DNS record")) { - $InnerParams = @{ - PiHoleServer = $PiHoleServer - Password = $Password - Element = $Element - Value = $Value - IgnoreSsl = $IgnoreSsl - RawOutput = $RawOutput - Confirm = $false - } - if ($PSBoundParameters.ContainsKey('Restart')) { - $InnerParams.Restart = $Restart - } + if ($PSCmdlet.ShouldProcess("Pi-Hole DNS record '$Value' ($Type)", "Remove DNS record")) { + $InnerParams = @{ + PiHoleServer = $PiHoleServer + Password = $Password + Element = $Element + Value = $Value + IgnoreSsl = $IgnoreSsl + RawOutput = $RawOutput + Confirm = $false + } + if ($PSBoundParameters.ContainsKey('Restart')) { + $InnerParams.Restart = $Restart + } - $Response = Remove-PiHoleConfigArrayItem @InnerParams -ErrorAction Stop + $Response = Remove-PiHoleConfigArrayItem @InnerParams -ErrorAction Stop - if ($RawOutput) { - Write-Output $Response - } - else { - $Object = [PSCustomObject]@{ - Type = $Type - Hostname = $Hostname - IPv4Address = $IPv4Address - IPv6Address = $IPv6Address - Target = $Target - Ttl = $Ttl - Status = $Response.Status + if ($RawOutput) { + Write-Output $Response + } + else { + $Object = [PSCustomObject]@{ + Type = $Type + Hostname = $Hostname + IPv4Address = $IPv4Address + IPv6Address = $IPv6Address + Target = $Target + Ttl = $Ttl + Status = $Response.Status + } + Write-Output $Object } - Write-Output $Object } } - } - catch { - Write-Error -Message $_.Exception.Message + catch { + Write-Error -Message $_.Exception.Message + } } } diff --git a/README.md b/README.md index a12ac50..311be4e 100644 --- a/README.md +++ b/README.md @@ -103,6 +103,7 @@ See [docs/EXAMPLES.md](docs/EXAMPLES.md) for real, captured output from every fu |---|---| | `Add-PiHoleDnsRecord` | Add a local DNS record | | `Get-PiHoleDnsBlockingStatus` | Get Pi-hole's current DNS blocking status | +| `Get-PiHoleDnsRecord` | Get local DNS records | | `Remove-PiHoleDnsRecord` | Remove a local DNS record | | `Set-PiHoleDnsBlocking` | Enable or disable Pi-hole's DNS blocking | diff --git a/docs/EXAMPLES.md b/docs/EXAMPLES.md index 3859b32..4faea3f 100644 --- a/docs/EXAMPLES.md +++ b/docs/EXAMPLES.md @@ -103,6 +103,24 @@ Ttl : Status : Added ``` +### Get-PiHoleDnsRecord + +_Can be filtered with -Type and/or -Hostname, and piped directly into Remove-PiHoleDnsRecord._ + +```powershell +Get-PiHoleDnsRecord -PiHoleServer $PiHoleServer -Password $Password +``` + +``` + +Type : A +Hostname : piholeshell-docs-dns-example.com +IPv4Address : 192.0.2.2 +IPv6Address : +Target : +Ttl : +``` + ### Remove-PiHoleDnsRecord ```powershell @@ -133,9 +151,9 @@ New-PiHoleGroup -PiHoleServer $PiHoleServer -Password $Password -GroupName "PiHo Name : PiHoleShellDocsExampleGroup Comment : Example group Enabled : True -Id : 62 -DateAdded : 10/12/2026 5:37:04 PM -DateModified : 10/12/2026 5:37:04 PM +Id : 48 +DateAdded : 10/12/2026 6:38:10 PM +DateModified : 10/12/2026 6:38:10 PM ``` ### Get-PiHoleGroup @@ -177,9 +195,9 @@ DateModified : 9/30/2026 8:48:26 AM Name : PiHoleShellDocsExampleGroup Comment : Example group Enabled : True -Id : 62 -DateAdded : 10/12/2026 5:37:04 PM -DateModified : 10/12/2026 5:37:04 PM +Id : 48 +DateAdded : 10/12/2026 6:38:10 PM +DateModified : 10/12/2026 6:38:10 PM ``` ### Update-PiHoleGroup @@ -193,9 +211,9 @@ Update-PiHoleGroup -PiHoleServer $PiHoleServer -Password $Password -GroupName "P Name : PiHoleShellDocsExampleGroup Comment : Example group Enabled : False -Id : 62 -DateAdded : 10/12/2026 5:37:04 PM -DateModified : 10/12/2026 5:37:22 PM +Id : 48 +DateAdded : 10/12/2026 6:38:10 PM +DateModified : 10/12/2026 6:38:42 PM ``` ### Remove-PiHoleGroup @@ -224,9 +242,9 @@ Address : https://blocklistproject.github.io/Lists/alt-version/ransomware Comment : Example list Groups : {Default} Enabled : True -Id : 79 -DateAdded : 10/12/2026 5:37:59 PM -DateModified : 10/12/2026 5:37:59 PM +Id : 67 +DateAdded : 10/12/2026 6:39:53 PM +DateModified : 10/12/2026 6:39:53 PM Type : Block DateUpdated : Number : 0 @@ -328,9 +346,9 @@ Address : https://blocklistproject.github.io/Lists/alt-version/ransomware Comment : Example list Groups : {Default} Enabled : False -Id : 79 -DateAdded : 10/12/2026 5:37:59 PM -DateModified : 10/12/2026 5:38:32 PM +Id : 67 +DateAdded : 10/12/2026 6:39:53 PM +DateModified : 10/12/2026 6:40:54 PM Type : Block DateUpdated : Number : 0 @@ -455,9 +473,9 @@ Kind : Exact Comment : Example domain Groups : {Default} Enabled : True -Id : 16 -DateAdded : 10/12/2026 5:39:10 PM -DateModified : 10/12/2026 5:39:10 PM +Id : 18 +DateAdded : 10/12/2026 6:42:07 PM +DateModified : 10/12/2026 6:42:07 PM ``` ### Get-PiHoleDomain @@ -475,9 +493,9 @@ Kind : exact Comment : Example domain Groups : {Default} Enabled : True -Id : 16 -DateAdded : 10/12/2026 5:39:10 PM -DateModified : 10/12/2026 5:39:10 PM +Id : 18 +DateAdded : 10/12/2026 6:42:07 PM +DateModified : 10/12/2026 6:42:07 PM ``` ### Update-PiHoleDomain @@ -495,9 +513,9 @@ Kind : Exact Comment : Example domain Groups : {Default} Enabled : False -Id : 16 -DateAdded : 10/12/2026 5:39:10 PM -DateModified : 10/12/2026 5:39:44 PM +Id : 18 +DateAdded : 10/12/2026 6:42:07 PM +DateModified : 10/12/2026 6:43:09 PM ``` ### Remove-PiHoleDomain @@ -528,9 +546,9 @@ Client : 192.168.99.99 Name : Comment : Example client Groups : {Default} -Id : 18 -DateAdded : 10/12/2026 5:40:15 PM -DateModified : 10/12/2026 5:40:15 PM +Id : 20 +DateAdded : 10/12/2026 6:44:07 PM +DateModified : 10/12/2026 6:44:07 PM ``` ### Get-PiHoleClient @@ -545,9 +563,9 @@ Client : 192.168.99.99 Name : Comment : Example client Groups : {Default} -Id : 18 -DateAdded : 10/12/2026 5:40:15 PM -DateModified : 10/12/2026 5:40:15 PM +Id : 20 +DateAdded : 10/12/2026 6:44:07 PM +DateModified : 10/12/2026 6:44:07 PM ``` ### Get-PiHoleClientSuggestion @@ -560,13 +578,13 @@ Get-PiHoleClientSuggestion -PiHoleServer $PiHoleServer -Password $Password HwAddr : ip-127.0.0.1 MacVendor : -LastQuery : 10/12/2026 5:36:48 PM +LastQuery : 10/12/2026 6:37:42 PM Addresses : 127.0.0.1 Names : localhost HwAddr : 74:56:3c:bb:f4:0b MacVendor : Giga-Byte Technology Co.,Ltd. -LastQuery : 10/12/2026 5:27:24 PM +LastQuery : 10/12/2026 6:31:26 PM Addresses : 192.168.1.162 Names : ``` @@ -583,9 +601,9 @@ Client : 192.168.99.99 Name : Comment : Updated comment Groups : {Default} -Id : 18 -DateAdded : 10/12/2026 5:40:15 PM -DateModified : 10/12/2026 5:40:53 PM +Id : 20 +DateAdded : 10/12/2026 6:44:07 PM +DateModified : 10/12/2026 6:45:19 PM ``` ### Remove-PiHoleClient @@ -610,18 +628,18 @@ Get-PiHoleStatsSummary -PiHoleServer $PiHoleServer -Password $Password ``` -Total : 310 -Blocked : 92 -PercentBlocked : 29.6774196624756 -UniqueDomains : 22 -Forwarded : 66 -Cached : 152 +Total : 41 +Blocked : 9 +PercentBlocked : 21.9512195587158 +UniqueDomains : 16 +Forwarded : 24 +Cached : 8 Frequency : 0 -Types : @{A=145; AAAA=145; ANY=0; SRV=0; SOA=0; PTR=20; TXT=0; NAPTR=0; MX=0; DS=0; RRSIG=0; DNSKEY=0; NS=0; SVCB=0; HTTPS=0; OTHER=0} -Status : @{Unknown=0; Gravity=92; Forwarded=66; Cache=122; Regex=0; DenyList=0; ExternalBlockedIp=0; ExternalBlockedNull=0; ExternalBlockedNxra=0; GravityCname=0; RegexCname=0; DenyListCname=0; Retired=0; RetiredDnssec=0; InProgress=0; Dbbusy=0; SpecialDomain=0; CacheStale=30; ExternalBlockedEde15=0} -Replies : @{Unknown=22; Nodata=23; Nxdomain=5; Cname=0; Ip=245; Domain=15; Rrname=0; ServFail=0; Refused=0; Notimp=0; Other=0; Dnssec=0; None=0; Blob=0} +Types : @{A=16; AAAA=17; ANY=0; SRV=0; SOA=0; PTR=8; TXT=0; NAPTR=0; MX=0; DS=0; RRSIG=0; DNSKEY=0; NS=0; SVCB=0; HTTPS=0; OTHER=0} +Status : @{Unknown=0; Gravity=9; Forwarded=24; Cache=8; Regex=0; DenyList=0; ExternalBlockedIp=0; ExternalBlockedNull=0; ExternalBlockedNxra=0; GravityCname=0; RegexCname=0; DenyListCname=0; Retired=0; RetiredDnssec=0; InProgress=0; Dbbusy=0; SpecialDomain=0; CacheStale=0; ExternalBlockedEde15=0} +Replies : @{Unknown=4; Nodata=3; Nxdomain=2; Cname=0; Ip=26; Domain=6; Rrname=0; ServFail=0; Refused=0; Notimp=0; Other=0; Dnssec=0; None=0; Blob=0} Clients : @{Active=2; Total=2} -Gravity : @{DomainsBeingBlocked=560453; LastUpdate=1791840963} +Gravity : @{DomainsBeingBlocked=560453; LastUpdate=1791845621} ``` ### Get-PiHoleStatsRecentBlocked @@ -632,7 +650,7 @@ Get-PiHoleStatsRecentBlocked -PiHoleServer $PiHoleServer -Password $Password ``` -Blocked : ads.pubmatic.com +Blocked : googleadservices.com ``` ### Get-PiHoleStatsQueryType @@ -644,10 +662,10 @@ Get-PiHoleStatsQueryType -PiHoleServer $PiHoleServer -Password $Password ``` Type : A -Count : 145 +Count : 16 Type : AAAA -Count : 145 +Count : 17 Type : ANY Count : 0 @@ -669,20 +687,20 @@ Get-PiHoleStatsTopDomain -PiHoleServer $PiHoleServer -Password $Password ``` -Domain : github.com -Count : 25 +Domain : wikipedia.org +Count : 4 -Domain : example.com -Count : 22 +Domain : bbc.com +Count : 4 -Domain : reddit.com -Count : 22 +Domain : mozilla.org +Count : 3 -Domain : python.org -Count : 19 +Domain : apple.com +Count : 3 -Domain : mozilla.org -Count : 18 +Domain : github.com +Count : 3 _(showing 5 of 10 results)_ ``` @@ -697,11 +715,11 @@ Get-PiHoleStatsTopClient -PiHoleServer $PiHoleServer -Password $Password IP : 192.168.1.162 Name : -Count : 290 +Count : 33 IP : 127.0.0.1 Name : localhost -Count : 20 +Count : 8 ``` ### Get-PiHoleStatsUpstream @@ -712,9 +730,9 @@ Get-PiHoleStatsUpstream -PiHoleServer $PiHoleServer -Password $Password ``` -TotalQueries : 310 -ForwardedQueries : 66 -Upstreams : {@{Ip=blocklist; Name=blocklist; Port=-1; Count=92; ResponseTime=0; Variance=0}, @{Ip=cache; Name=cache; Port=-1; Count=152; ResponseTime=0; Variance=0}, @{Ip=8.8.4.4; Name=dns.google; Port=53; Count=59; ResponseTime=0; Variance=0}, @{Ip=8.8.8.8; Name=dns.google; Port=53; Count=7; ResponseTime=0; Variance=0}} +TotalQueries : 41 +ForwardedQueries : 24 +Upstreams : {@{Ip=blocklist; Name=blocklist; Port=-1; Count=9; ResponseTime=0; Variance=0}, @{Ip=cache; Name=cache; Port=-1; Count=8; ResponseTime=0; Variance=0}, @{Ip=8.8.4.4; Name=dns.google; Port=53; Count=22; ResponseTime=0; Variance=0}, @{Ip=8.8.8.8; Name=dns.google; Port=53; Count=2; ResponseTime=0; Variance=0}} ``` ### Get-PiHoleStatsQuerySuggestions @@ -725,7 +743,7 @@ Get-PiHoleStatsQuerySuggestions -PiHoleServer $PiHoleServer -Password $Password ``` -Domain : {github.com, example.com, reddit.com, python.org…} +Domain : {wikipedia.org, bbc.com, mozilla.org, apple.com…} ClientIp : {192.168.1.162, 127.0.0.1} ClientName : {localhost} Upstream : {blocklist, cache, 8.8.4.4#53 (dns.google), 8.8.8.8#53 (dns.google)…} @@ -745,9 +763,9 @@ Get-PiHoleStatsDatabaseSummary -PiHoleServer $PiHoleServer -Password $Password ``` -SumQueries : 310 -SumBlocked : 92 -PercentBlocked : 29.6774196624756 +SumQueries : 41 +SumBlocked : 9 +PercentBlocked : 21.9512195587158 TotalClients : 3 ``` @@ -762,7 +780,7 @@ Get-PiHoleStatsDatabaseQueryType -PiHoleServer $PiHoleServer -Password $Password ``` Type : A -Count : 145 +Count : 17 Type : AAAA Count : 0 @@ -774,7 +792,7 @@ Type : SRV Count : 0 Type : SOA -Count : 20 +Count : 8 _(showing 5 of 16 results)_ ``` @@ -789,20 +807,20 @@ Get-PiHoleStatsDatabaseTopDomain -PiHoleServer $PiHoleServer -Password $Password ``` -Domain : github.com -Count : 25 +Domain : bbc.com +Count : 4 -Domain : example.com -Count : 22 +Domain : wikipedia.org +Count : 4 -Domain : reddit.com -Count : 22 +Domain : mozilla.org +Count : 3 -Domain : python.org -Count : 19 +Domain : stackoverflow.com +Count : 3 -Domain : mozilla.org -Count : 18 +Domain : apple.com +Count : 3 _(showing 5 of 10 results)_ ``` @@ -819,11 +837,11 @@ Get-PiHoleStatsDatabaseTopClient -PiHoleServer $PiHoleServer -Password $Password IP : 192.168.1.162 Name : -Count : 198 +Count : 24 IP : 127.0.0.1 Name : localhost -Count : 17 +Count : 5 IP : 127.0.0.1 Name : @@ -840,9 +858,9 @@ Get-PiHoleStatsDatabaseUpstream -PiHoleServer $PiHoleServer -Password $Password ``` -TotalQueries : 310 -ForwardedQueries : 66 -Upstreams : {@{Ip=1; Name=; Port=-1; Count=59; ResponseTime=0; Variance=0}, @{Ip=2; Name=; Port=-1; Count=7; ResponseTime=0; Variance=0}, @{Ip=cache; Name=cache; Port=-1; Count=122; ResponseTime=0; Variance=0}, @{Ip=blocklist; Name=blocklist; Port=-1; Count=122; ResponseTime=0; Variance=0}} +TotalQueries : 41 +ForwardedQueries : 24 +Upstreams : {@{Ip=1; Name=; Port=-1; Count=22; ResponseTime=0; Variance=0}, @{Ip=2; Name=; Port=-1; Count=2; ResponseTime=0; Variance=0}, @{Ip=cache; Name=cache; Port=-1; Count=8; ResponseTime=0; Variance=0}, @{Ip=blocklist; Name=blocklist; Port=-1; Count=9; ResponseTime=0; Variance=0}} ``` ### Get-PiHoleQuery @@ -855,69 +873,69 @@ Get-PiHoleQuery -PiHoleServer $PiHoleServer -Password $Password -Length 5 ``` -Id : 309 -Time : 10/12/2026 5:36:49 PM +Id : 40 +Time : 10/12/2026 6:37:42 PM Type : PTR -Domain : 4.4.8.8.in-addr.arpa +Domain : 8.8.8.8.in-addr.arpa Cname : Status : FORWARDED Client : @{Ip=127.0.0.1; Name=localhost} Dnssec : UNKNOWN -Reply : @{Type=DOMAIN; Time=0.0182390213012695} +Reply : @{Type=DOMAIN; Time=0.0698070526123047} ListId : -Upstream : 8.8.4.4#53 +Upstream : 8.8.8.8#53 Ede : @{Code=-1; Text=} -Id : 308 -Time : 10/12/2026 5:36:49 PM +Id : 39 +Time : 10/12/2026 6:37:41 PM Type : PTR -Domain : 8.8.8.8.in-addr.arpa +Domain : 4.4.8.8.in-addr.arpa Cname : Status : FORWARDED Client : @{Ip=127.0.0.1; Name=localhost} Dnssec : UNKNOWN -Reply : @{Type=DOMAIN; Time=0.0416350364685059} +Reply : @{Type=DOMAIN; Time=0.0369069576263428} ListId : -Upstream : 8.8.4.4#53 +Upstream : 8.8.8.8#53 Ede : @{Code=-1; Text=} -Id : 307 -Time : 10/12/2026 5:36:49 PM +Id : 38 +Time : 10/12/2026 6:37:41 PM Type : PTR Domain : 1.0.0.127.in-addr.arpa Cname : Status : CACHE Client : @{Ip=127.0.0.1; Name=localhost} Dnssec : UNKNOWN -Reply : @{Type=DOMAIN; Time=0.00114893913269043} +Reply : @{Type=DOMAIN; Time=0.00117111206054688} ListId : Upstream : Ede : @{Code=-1; Text=} -Id : 306 -Time : 10/12/2026 5:36:49 PM +Id : 37 +Time : 10/12/2026 6:37:41 PM Type : PTR Domain : 162.1.168.192.in-addr.arpa Cname : Status : CACHE Client : @{Ip=127.0.0.1; Name=localhost} Dnssec : UNKNOWN -Reply : @{Type=NXDOMAIN; Time=0.0187718868255615} +Reply : @{Type=NXDOMAIN; Time=0.0176899433135986} ListId : Upstream : Ede : @{Code=-1; Text=} -Id : 305 -Time : 10/12/2026 5:28:23 PM +Id : 36 +Time : 10/12/2026 6:31:28 PM Type : PTR -Domain : 4.4.8.8.in-addr.arpa +Domain : 1.0.0.127.in-addr.arpa Cname : -Status : FORWARDED +Status : CACHE Client : @{Ip=127.0.0.1; Name=localhost} Dnssec : UNKNOWN -Reply : @{Type=DOMAIN; Time=0.0437800884246826} +Reply : @{Type=DOMAIN; Time=0.00136184692382812} ListId : -Upstream : 8.8.4.4#53 +Upstream : Ede : @{Code=-1; Text=} ``` @@ -1030,20 +1048,20 @@ CpuPercent : 0 MemoryPercent : 0 ActiveClients : 2 Blocking : enabled -Cache : @{Size=10000; Inserted=2; Evicted=0} +Cache : @{Size=10000; Inserted=30; Evicted=0} Config : @{DhcpActive=False; DhcpStart=; DhcpEnd=; DhcpIpv6=False; DnsDnssec=False; DnsDomain=lan; DnsNumUpstreams=2; DnsPort=53; DnsrevServerAactive=False; PrivacyLevel=0} GravitySize : 560453 HostModel : Raspberry Pi Zero W Rev 1.1 IFace : @{v4=; v6=} NodeName : dns3.localdomain Pid : 388 -Queries : @{Total=306; Blocked=92; PercentBlocked=30.0653591156006; QueryFrequency=0} -RecentBlocked : ads.pubmatic.com -Sensors : @{CpuTemp=41.698; HotLimit=60; Unit=C} -System : @{Uptime=152421; Memory=; Procs=73; Cpu=; Ftl=} -TopBlocked : googleadservices.com +Queries : @{Total=37; Blocked=9; PercentBlocked=24.3243236541748; QueryFrequency=0} +RecentBlocked : googleadservices.com +Sensors : @{CpuTemp=43.312; HotLimit=60; Unit=C} +System : @{Uptime=156002; Memory=; Procs=74; Cpu=; Ftl=} +TopBlocked : doubleclick.net TopClient : 192.168.1.162 -TopDomain : github.com +TopDomain : bbc.com Version : @{Core=; Web=; Ftl=; Docker=} ``` @@ -1080,11 +1098,11 @@ Get-PiHoleInfoSystem -PiHoleServer $PiHoleServer -Password $Password ``` -Uptime : 152431 +Uptime : 156022 Memory : @{Ram=; Swap=} -Procs : 73 -Cpu : @{NumProcessors=1; PercentCpu=95.3000030517578; Load=} -Ftl : @{PercentMemory=2.54814767837524; PercentCpu=94.9000015258789} +Procs : 74 +Cpu : @{NumProcessors=1; PercentCpu=100.099998474121; Load=} +Ftl : @{PercentMemory=2.43389201164246; PercentCpu=99.3000030517578} ``` ### Get-PiHoleInfoFtl @@ -1100,11 +1118,11 @@ PrivacyLevel : 0 QueryFrequency : 0 Clients : @{Total=2; Active=2} Pid : 388 -Uptime : 442841.840855 -PercentMemory : 2.54814767837524 -PercentCpu : 95.6999969482422 +Uptime : 979769.972744 +PercentMemory : 2.42485022544861 +PercentCpu : 99.1999969482422 AllowDestructive : True -Dnsmasq : @{DnsCacheInserted=2; DnsCacheLiveFreed=0; DnsQueriesForwarded=2; DnsAuthAnswered=0; DnsLocalAnswered=2; DnsStaleAnswered=0; DnsUnanswered=0; DnssecMaxCryptoUse=0; DnssecMaxSigFail=0; DnssecMaxWork=0; Bootp=0; Pxe=0; DhcpAck=0; DhcpDecline=0; DhcpDiscover=0; DhcpInform=0; DhcpNak=0; DhcpOffer=0; DhcpRelease=0; DhcpRequest=0; Noanswer=0; LeasesAllocated4=0; LeasesPruned4=0; LeasesAllocated6=0; LeasesPruned6=0; TcpConnections=0; DhcpLeasequery=0; DhcpLeaseUnassigned=0; DhcpLeaseActve=0; DhcpLeaseUnknown=0} +Dnsmasq : @{DnsCacheInserted=30; DnsCacheLiveFreed=0; DnsQueriesForwarded=22; DnsAuthAnswered=0; DnsLocalAnswered=15; DnsStaleAnswered=0; DnsUnanswered=0; DnssecMaxCryptoUse=0; DnssecMaxSigFail=0; DnssecMaxWork=0; Bootp=0; Pxe=0; DhcpAck=0; DhcpDecline=0; DhcpDiscover=0; DhcpInform=0; DhcpNak=0; DhcpOffer=0; DhcpRelease=0; DhcpRequest=0; Noanswer=0; LeasesAllocated4=0; LeasesPruned4=0; LeasesAllocated6=0; LeasesPruned6=0; TcpConnections=0; DhcpLeasequery=0; DhcpLeaseUnassigned=0; DhcpLeaseActve=0; DhcpLeaseUnknown=0} ``` ### Get-PiHoleInfoSensors @@ -1116,7 +1134,7 @@ Get-PiHoleInfoSensors -PiHoleServer $PiHoleServer -Password $Password ``` List : {@{Name=cpu_thermal; Path=hwmon0; Source=devices/virtual/thermal/thermal_zone0; Temps=}, @{Name=rpi_volt; Path=hwmon1; Source=devices/platform/soc/soc:firmware/raspberrypi-hwmon; Temps=}} -CpuTemp : 41.698 +CpuTemp : 43.312 HotLimit : 60 Unit : C ``` @@ -1133,13 +1151,13 @@ Size : 13983744 Type : Regular file Mode : rw-r----- AccessTime : 6/25/2025 12:32:44 AM -ModifiedTime : 10/12/2026 5:28:19 PM -ChangeTime : 10/12/2026 5:28:19 PM +ModifiedTime : 10/12/2026 6:19:17 PM +ChangeTime : 10/12/2026 6:19:17 PM Owner : @{User=; Group=} -Queries : 306 -EarliestTimestamp : 10/11/2026 5:30:00 PM -QueriesDisk : 306 -EarliestTimestampDisk : 10/12/2026 5:12:02 PM +Queries : 37 +EarliestTimestamp : 10/11/2026 6:30:00 PM +QueriesDisk : 37 +EarliestTimestampDisk : SqliteVersion : 3.53.1 ``` @@ -1208,10 +1226,10 @@ Get-PiHoleInfoMessage -PiHoleServer $PiHoleServer -Password $Password ``` Id : 1 -Timestamp : 10/12/2026 5:28:21 PM +Timestamp : 10/12/2026 6:34:19 PM Type : LOAD -Plain : Long-term load (15min avg) larger than number of processors: 1.2 > 1 -Html : Long-term load (15min avg) larger than number of processors: 1.2 > 1
This may slow down DNS resolution and can cause bottlenecks. +Plain : Long-term load (15min avg) larger than number of processors: 1.9 > 1 +Html : Long-term load (15min avg) larger than number of processors: 1.9 > 1
This may slow down DNS resolution and can cause bottlenecks. ``` ### Get-PiHoleInfoMessageCount @@ -1246,8 +1264,8 @@ Get-PiHoleLogWebserver -PiHoleServer $PiHoleServer -Password $Password ``` -Log : {@{Timestamp=10/12/2026 5:28:21 PM; Message=Initializing HTTP server on ports "8089,8489s"; Priority=}, @{Timestamp=10/12/2026 5:34:46 PM; Message=ACCESS: 192.168.1.162 - - [12/Oct/2026:22:34:45 +0000] "PATCH /api/config?restart=false HTTP/1.1" 200 4589 - Mozilla/5.0 (Windows NT 10.0; Microsoft Windows 10.0.26200; en-US) PowerShell/7.6.6; Priority=}, @{Timestamp=10/12/2026 5:34:46 PM; Message=ACCESS: 192.168.1.162 - - [12/Oct/2026:22:34:46 +0000] "DELETE /api/auth HTTP/1.1" 204 558 - Mozilla/5.0 (Windows NT 10.0; Microsoft Windows 10.0.26200; en-US) PowerShell/7.6.6; Priority=}, @{Timestamp=10/12/2026 5:34:51 PM; Message=ACCESS: 192.168.1.162 - - [12/Oct/2026:22:34:46 +0000] "POST /api/auth HTTP/1.1" 200 806 - Mozilla/5.0 (Windows NT 10.0; Microsoft Windows 10.0.26200; en-US) PowerShell/7.6.6; Priority=}} -NextID : 4 +Log : {@{Timestamp=10/12/2026 6:19:19 PM; Message=Initializing HTTP server on ports "8089,8489s"; Priority=}, @{Timestamp=10/12/2026 6:33:39 PM; Message=ACCESS: 192.168.1.162 - - [12/Oct/2026:23:33:38 +0000] "PATCH /api/config?restart=false HTTP/1.1" 200 4589 - Mozilla/5.0 (Windows NT 10.0; Microsoft Windows 10.0.26200; en-US) PowerShell/7.6.6; Priority=}, @{Timestamp=10/12/2026 6:33:39 PM; Message=ACCESS: 192.168.1.162 - - [12/Oct/2026:23:33:38 +0000] "DELETE /api/auth HTTP/1.1" 204 558 - Mozilla/5.0 (Windows NT 10.0; Microsoft Windows 10.0.26200; en-US) PowerShell/7.6.6; Priority=}, @{Timestamp=10/12/2026 6:33:42 PM; Message=ACCESS: 192.168.1.162 - - [12/Oct/2026:23:33:33 +0000] "POST /api/auth HTTP/1.1" 200 808 - Mozilla/5.0 (Windows NT 10.0; Microsoft Windows 10.0.26200; en-US) PowerShell/7.6.6; Priority=}…} +NextID : 7 Pid : 388 File : /var/log/pihole/webserver.log ``` @@ -1260,8 +1278,8 @@ Get-PiHoleLogDnsmasq -PiHoleServer $PiHoleServer -Password $Password ``` -Log : {@{Timestamp=10/12/2026 5:28:21 PM; Message=started, version pi-hole-v2.93 cachesize 10000; Priority=}, @{Timestamp=10/12/2026 5:28:21 PM; Message=DNS service limited to local subnets; Priority=}, @{Timestamp=10/12/2026 5:28:21 PM; Message=compile time options: IPv6 GNU-getopt no-DBus no-UBus no-i18n IDN2 DHCP DHCPv6 Lua TFTP no-conntrack ipset no-nftset auth DNSSEC loop-detect inotify dumpfile; Priority=}, @{Timestamp=10/12/2026 5:28:21 PM; Message=using nameserver 8.8.8.8#53; Priority=}…} -NextID : 51 +Log : {@{Timestamp=10/12/2026 6:19:19 PM; Message=started, version pi-hole-v2.93 cachesize 10000; Priority=}, @{Timestamp=10/12/2026 6:19:19 PM; Message=DNS service limited to local subnets; Priority=}, @{Timestamp=10/12/2026 6:19:19 PM; Message=compile time options: IPv6 GNU-getopt no-DBus no-UBus no-i18n IDN2 DHCP DHCPv6 Lua TFTP no-conntrack ipset no-nftset auth DNSSEC loop-detect inotify dumpfile; Priority=}, @{Timestamp=10/12/2026 6:19:19 PM; Message=using nameserver 8.8.8.8#53; Priority=}…} +NextID : 39 Pid : 388 File : /var/log/pihole/pihole.log ``` @@ -1274,8 +1292,8 @@ Get-PiHoleLogFtl -PiHoleServer $PiHoleServer -Password $Password ``` -Log : {@{Timestamp=10/12/2026 5:28:20 PM; Message=PID of FTL process: 388; Priority=INFO}, @{Timestamp=10/12/2026 5:28:20 PM; Message=listening on 0.0.0.0 port 53; Priority=INFO}, @{Timestamp=10/12/2026 5:28:20 PM; Message=listening on :: port 53; Priority=INFO}, @{Timestamp=10/12/2026 5:28:20 PM; Message=Database version is 22; Priority=INFO}…} -NextID : 180 +Log : {@{Timestamp=10/12/2026 6:19:18 PM; Message=PID of FTL process: 388; Priority=INFO}, @{Timestamp=10/12/2026 6:19:18 PM; Message=listening on 0.0.0.0 port 53; Priority=INFO}, @{Timestamp=10/12/2026 6:19:18 PM; Message=listening on :: port 53; Priority=INFO}, @{Timestamp=10/12/2026 6:19:18 PM; Message=Database version is 22; Priority=INFO}…} +NextID : 237 Pid : 388 File : /var/log/pihole/FTL.log ``` @@ -1317,31 +1335,31 @@ Get-PiHoleHistory -PiHoleServer $PiHoleServer -Password $Password ``` -Timestamp : 10/11/2026 5:45:00 PM +Timestamp : 10/11/2026 6:45:00 PM Total : 0 Cached : 0 Blocked : 0 Forwarded : 0 -Timestamp : 10/11/2026 5:55:00 PM +Timestamp : 10/11/2026 6:55:00 PM Total : 0 Cached : 0 Blocked : 0 Forwarded : 0 -Timestamp : 10/11/2026 6:05:00 PM +Timestamp : 10/11/2026 7:05:00 PM Total : 0 Cached : 0 Blocked : 0 Forwarded : 0 -Timestamp : 10/11/2026 6:15:00 PM +Timestamp : 10/11/2026 7:15:00 PM Total : 0 Cached : 0 Blocked : 0 Forwarded : 0 -Timestamp : 10/11/2026 6:25:00 PM +Timestamp : 10/11/2026 7:25:00 PM Total : 0 Cached : 0 Blocked : 0 @@ -1358,19 +1376,19 @@ Get-PiHoleHistoryClient -PiHoleServer $PiHoleServer -Password $Password ``` -Timestamp : 10/11/2026 5:45:00 PM +Timestamp : 10/11/2026 6:45:00 PM Clients : {@{IP=192.168.1.162; Name=; Count=0}, @{IP=127.0.0.1; Name=localhost; Count=0}, @{IP=others; Name=; Count=0}} -Timestamp : 10/11/2026 5:55:00 PM +Timestamp : 10/11/2026 6:55:00 PM Clients : {@{IP=192.168.1.162; Name=; Count=0}, @{IP=127.0.0.1; Name=localhost; Count=0}, @{IP=others; Name=; Count=0}} -Timestamp : 10/11/2026 6:05:00 PM +Timestamp : 10/11/2026 7:05:00 PM Clients : {@{IP=192.168.1.162; Name=; Count=0}, @{IP=127.0.0.1; Name=localhost; Count=0}, @{IP=others; Name=; Count=0}} -Timestamp : 10/11/2026 6:15:00 PM +Timestamp : 10/11/2026 7:15:00 PM Clients : {@{IP=192.168.1.162; Name=; Count=0}, @{IP=127.0.0.1; Name=localhost; Count=0}, @{IP=others; Name=; Count=0}} -Timestamp : 10/11/2026 6:25:00 PM +Timestamp : 10/11/2026 7:25:00 PM Clients : {@{IP=192.168.1.162; Name=; Count=0}, @{IP=127.0.0.1; Name=localhost; Count=0}, @{IP=others; Name=; Count=0}} _(showing 5 of 145 results)_ @@ -1386,23 +1404,11 @@ Get-PiHoleHistoryDatabase -PiHoleServer $PiHoleServer -Password $Password ``` -Timestamp : 10/12/2026 5:10:00 PM -Total : 50 -Cached : 14 -Blocked : 2 -Forwarded : 34 - -Timestamp : 10/12/2026 5:20:00 PM -Total : 256 -Cached : 136 -Blocked : 90 -Forwarded : 30 - -Timestamp : 10/12/2026 5:30:00 PM -Total : 4 -Cached : 2 -Blocked : 0 -Forwarded : 2 +Timestamp : 10/12/2026 6:30:00 PM +Total : 41 +Cached : 8 +Blocked : 9 +Forwarded : 24 ``` ### Get-PiHoleHistoryDatabaseClient @@ -1415,13 +1421,7 @@ Get-PiHoleHistoryDatabaseClient -PiHoleServer $PiHoleServer -Password $Password ``` -Timestamp : 10/12/2026 5:30:00 PM -Clients : @{ClientId=3; Count=1} - -Timestamp : 10/12/2026 5:20:00 PM -Clients : {@{ClientId=3; Count=1}, @{ClientId=5; Count=1}} - -Timestamp : 10/12/2026 5:10:00 PM +Timestamp : 10/12/2026 6:30:00 PM Clients : {@{ClientId=3; Count=1}, @{ClientId=2; Count=1}, @{ClientId=5; Count=1}} ``` @@ -1518,7 +1518,7 @@ ProtoDown : False Address : 00:00:00:00:00:00 Broadcast : 00:00:00:00:00:00 Stats : @{RxBytes=; TxBytes=; Bits=64} -Addresses : {@{Family=inet; Scope=host; Flags=permanent; Prefixlen=8; Address=127.0.0.1; AddressType=loopback; Local=127.0.0.1; LocalType=loopback; Label=lo; Prefered=4294967295; Valid=4294967295; Cstamp=1791692111.02; Tstamp=1791692111.02}, @{Family=inet6; Scope=host; Flags=permanent; Prefixlen=128; Address=::1; AddressType=loopback; Prefered=4294967295; Valid=4294967295; Cstamp=1791692111.02; Tstamp=1791692111.02}} +Addresses : {@{Family=inet; Scope=host; Flags=permanent; Prefixlen=8; Address=127.0.0.1; AddressType=loopback; Local=127.0.0.1; LocalType=loopback; Label=lo; Prefered=4294967295; Valid=4294967295; Cstamp=1791692112.02; Tstamp=1791692112.02}, @{Family=inet6; Scope=host; Flags=permanent; Prefixlen=128; Address=::1; AddressType=loopback; Prefered=4294967295; Valid=4294967295; Cstamp=1791692112.02; Tstamp=1791692112.02}} Name : wlan0 Speed : @@ -1531,7 +1531,7 @@ Address : b8:27:eb:11:a4:d5 Broadcast : ff:ff:ff:ff:ff:ff PermAddress : b8:27:eb:11:a4:d5 Stats : @{RxBytes=; TxBytes=; Bits=64} -Addresses : {@{Family=inet; Scope=universe; Flags=; Prefixlen=24; Address=192.168.1.248; AddressType=private; Local=192.168.1.248; LocalType=private; Broadcast=192.168.1.255; BroadcastType=private; Label=wlan0; Prefered=74660; Valid=74660; Cstamp=1791692137.78; Tstamp=1791833219.34}, @{Family=inet6; Scope=link; Flags=permanent; Prefixlen=64; Address=fe80::ba27:ebff:fe11:a4d5; AddressType=link-local (LL); Prefered=4294967295; Valid=4294967295; Cstamp=1791692130.87; Tstamp=1791692130.87}} +Addresses : {@{Family=inet; Scope=universe; Flags=; Prefixlen=24; Address=192.168.1.248; AddressType=private; Local=192.168.1.248; LocalType=private; Broadcast=192.168.1.255; BroadcastType=private; Label=wlan0; Prefered=70695; Valid=70695; Cstamp=1791692138.78; Tstamp=1791833220.34}, @{Family=inet6; Scope=link; Flags=permanent; Prefixlen=64; Address=fe80::ba27:ebff:fe11:a4d5; AddressType=link-local (LL); Prefered=4294967295; Valid=4294967295; Cstamp=1791692131.87; Tstamp=1791692131.87}} ``` ### Get-PiHoleNetworkDevice @@ -1547,20 +1547,20 @@ Get-PiHoleNetworkDevice -PiHoleServer $PiHoleServer -Password $Password Id : 2 HwAddr : ip-127.0.0.1 Interface : lo -FirstSeen : 10/12/2026 5:12:02 PM -LastQuery : 10/12/2026 5:36:48 PM -NumQueries : 24 +FirstSeen : 10/12/2026 6:31:26 PM +LastQuery : 10/12/2026 6:37:42 PM +NumQueries : 9 MacVendor : -Ips : @{Ip=127.0.0.1; Name=localhost; LastSeen=10/12/2026 5:42:00 PM; NameUpdated=10/12/2026 5:42:00 PM} +Ips : @{Ip=127.0.0.1; Name=localhost; LastSeen=10/12/2026 6:48:00 PM; NameUpdated=10/12/2026 6:48:00 PM} Id : 1 HwAddr : 74:56:3c:bb:f4:0b Interface : wlan0 -FirstSeen : 10/12/2026 5:12:01 PM -LastQuery : 10/12/2026 5:27:24 PM -NumQueries : 268 +FirstSeen : 10/12/2026 6:31:26 PM +LastQuery : 10/12/2026 6:31:26 PM +NumQueries : 34 MacVendor : Giga-Byte Technology Co.,Ltd. -Ips : @{Ip=192.168.1.162; Name=; LastSeen=10/12/2026 5:42:00 PM; NameUpdated=12/31/1969 6:00:00 PM} +Ips : @{Ip=192.168.1.162; Name=; LastSeen=10/12/2026 6:48:00 PM; NameUpdated=12/31/1969 6:00:00 PM} ``` ### Remove-PiHoleNetworkDevice @@ -1613,8 +1613,8 @@ Get-PiHoleAuthStatus -PiHoleServer $PiHoleServer -Password $Password Valid : True Totp : False -Sid : hC4IO7uXkDyqfnkruxSkQw= -Csrf : kW1Eb243nJQ7vpBky2AX3A= +Sid : zH7Z6NLKzAHxBNREdG6N5g= +Csrf : CgJVzV6Gp2nM1JY5ibWxpQ= Validity : 1800 Message : correct password ``` @@ -1634,8 +1634,8 @@ Algorithm : SHA1 Digits : 6 Period : 30 Offset : 0 -Secret : P4HHFM7JOMC7N4XN7ACW2FITOZBYNOR3 -Codes : {630810, 93752, 414226, 216678…} +Secret : NQFB3X5S7SUPU3UZKSLNTHJEXLKJPZP4 +Codes : {282924, 721698, 735368, 749478…} ``` ### Get-PiHoleCurrentAuthSession @@ -1651,9 +1651,9 @@ CurrentSession : False Valid : True TlsLogin : True TlsMixed : False -LoginAt : 10/12/2026 5:26:22 PM -LastActive : 10/12/2026 5:26:22 PM -ValidUntil : 10/12/2026 5:56:22 PM +LoginAt : 10/12/2026 6:19:07 PM +LastActive : 10/12/2026 6:19:15 PM +ValidUntil : 10/12/2026 6:49:15 PM RemoteAddress : 192.168.1.162 UserAgent : Mozilla/5.0 (Windows NT 10.0; Microsoft Windows 10.0.26200; en-US) PowerShell/7.6.6 XForwardedFor : @@ -1665,9 +1665,9 @@ CurrentSession : False Valid : True TlsLogin : True TlsMixed : False -LoginAt : 10/12/2026 5:27:32 PM -LastActive : 10/12/2026 5:27:41 PM -ValidUntil : 10/12/2026 5:57:41 PM +LoginAt : 10/12/2026 6:19:11 PM +LastActive : 10/12/2026 6:19:11 PM +ValidUntil : 10/12/2026 6:49:11 PM RemoteAddress : 192.168.1.162 UserAgent : Mozilla/5.0 (Windows NT 10.0; Microsoft Windows 10.0.26200; en-US) PowerShell/7.6.6 XForwardedFor : @@ -1675,13 +1675,27 @@ App : True Cli : False Id : 2 +CurrentSession : False +Valid : True +TlsLogin : True +TlsMixed : False +LoginAt : 10/12/2026 6:31:46 PM +LastActive : 10/12/2026 6:31:46 PM +ValidUntil : 10/12/2026 7:01:46 PM +RemoteAddress : 192.168.1.162 +UserAgent : Mozilla/5.0 (Windows NT 10.0; Microsoft Windows 10.0.26200; en-US) PowerShell/7.6.6 +XForwardedFor : +App : True +Cli : False + +Id : 3 CurrentSession : True Valid : True TlsLogin : True TlsMixed : False -LoginAt : 10/12/2026 5:33:50 PM -LastActive : 10/12/2026 5:33:55 PM -ValidUntil : 10/12/2026 6:03:55 PM +LoginAt : 10/12/2026 6:31:53 PM +LastActive : 10/12/2026 6:32:01 PM +ValidUntil : 10/12/2026 7:02:01 PM RemoteAddress : 192.168.1.162 UserAgent : Mozilla/5.0 (Windows NT 10.0; Microsoft Windows 10.0.26200; en-US) PowerShell/7.6.6 XForwardedFor : diff --git a/tests/DnsControl/Get-PiHoleDnsRecord.Integration.Tests.ps1 b/tests/DnsControl/Get-PiHoleDnsRecord.Integration.Tests.ps1 new file mode 100644 index 0000000..637ef28 --- /dev/null +++ b/tests/DnsControl/Get-PiHoleDnsRecord.Integration.Tests.ps1 @@ -0,0 +1,106 @@ +# Requires -Module Pester +# +# Integration tests that call a REAL Pi-hole server. Configure tests/IntegrationConfig.local.ps1 +# (copy it from IntegrationConfig.example.ps1) before running. Tests are skipped automatically +# if that file is missing. +# +# NOTE: these tests add/remove fake records using TEST-NET-1/documentation (RFC 5737/3849) +# reserved addresses that will never route anywhere real. -Restart $false is used throughout to +# avoid the brief FTL restart a real config change otherwise triggers. + +$script:ConfigAvailable = Test-Path (Join-Path (Split-Path $PSScriptRoot -Parent) 'IntegrationConfig.local.ps1') + +Describe 'Get-PiHoleDnsRecord (Integration)' -Tag 'Integration' { + BeforeAll { + Import-Module .\PiHoleShell\PiHoleShell.psm1 -Force + + $script:AHostname = 'piholeshell-test-get-a.example.com' + $script:AIPv4 = '192.0.2.203' + $script:CnameHostname = 'piholeshell-test-get-cname.example.com' + $script:CnameTarget = 'piholeshell-test-get-a.example.com' + $script:CnameTtl = 300 + + $configPath = Join-Path (Split-Path $PSScriptRoot -Parent) 'IntegrationConfig.local.ps1' + if (Test-Path $configPath) { + . $configPath + $script:PiHoleServer = $PiHoleServer + $script:PiHoleToken = $PiHoleToken + $script:PiHoleIgnoreSsl = $PiHoleIgnoreSsl + + # Defensive cleanup in case a previous failed run left these behind + Remove-PiHoleConfigArrayItem -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Element 'dns/hosts' -Value "$script:AIPv4 $script:AHostname" -Restart $false -Confirm:$false -ErrorAction SilentlyContinue -WarningAction SilentlyContinue | Out-Null + Remove-PiHoleConfigArrayItem -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Element 'dns/cnameRecords' -Value "$script:CnameHostname,$script:CnameTarget,$script:CnameTtl" -Restart $false -Confirm:$false -ErrorAction SilentlyContinue -WarningAction SilentlyContinue | Out-Null + + Add-PiHoleConfigArrayItem -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Element 'dns/hosts' -Value "$script:AIPv4 $script:AHostname" -Restart $false | Out-Null + Add-PiHoleConfigArrayItem -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Element 'dns/cnameRecords' -Value "$script:CnameHostname,$script:CnameTarget,$script:CnameTtl" -Restart $false | Out-Null + } + } + + AfterAll { + if ($script:PiHoleServer) { + Remove-PiHoleConfigArrayItem -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Element 'dns/hosts' -Value "$script:AIPv4 $script:AHostname" -Restart $false -Confirm:$false -ErrorAction SilentlyContinue | Out-Null + Remove-PiHoleConfigArrayItem -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Element 'dns/cnameRecords' -Value "$script:CnameHostname,$script:CnameTarget,$script:CnameTtl" -Restart $false -Confirm:$false -ErrorAction SilentlyContinue | Out-Null + } + } + + It 'returns both the A and CNAME test records, correctly typed' -Skip:(-not $script:ConfigAvailable) { + $result = Get-PiHoleDnsRecord -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl + $result | Where-Object { $_.Hostname -in @($script:AHostname, $script:CnameHostname) } | Format-Table | Out-String | Write-Host + + $aRecord = $result | Where-Object { $_.Hostname -eq $script:AHostname } + $aRecord | Should -Not -BeNullOrEmpty + $aRecord.Type | Should -Be 'A' + $aRecord.IPv4Address | Should -Be $script:AIPv4 + + $cnameRecord = $result | Where-Object { $_.Hostname -eq $script:CnameHostname } + $cnameRecord | Should -Not -BeNullOrEmpty + $cnameRecord.Type | Should -Be 'CNAME' + $cnameRecord.Target | Should -Be $script:CnameTarget + $cnameRecord.Ttl | Should -Be $script:CnameTtl + } + + It 'filters by -Type' -Skip:(-not $script:ConfigAvailable) { + $result = Get-PiHoleDnsRecord -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Type CNAME + + $result | Should -Not -BeNullOrEmpty + ($result.Type | Select-Object -Unique) | Should -Be 'CNAME' + $result.Hostname | Should -Contain $script:CnameHostname + } + + It 'filters by -Hostname' -Skip:(-not $script:ConfigAvailable) { + $result = Get-PiHoleDnsRecord -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Hostname $script:AHostname + + $result | Should -Not -BeNullOrEmpty + @($result).Count | Should -Be 1 + $result.Type | Should -Be 'A' + } + + It 'returns the raw API response when RawOutput is set' -Skip:(-not $script:ConfigAvailable) { + $result = Get-PiHoleDnsRecord -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -RawOutput $true + + $result.PSObject.Properties.Name | Should -Contain 'Hosts' + $result.PSObject.Properties.Name | Should -Contain 'CnameRecords' + $result.Hosts | Should -Contain "$script:AIPv4 $script:AHostname" + } + + It 'can be piped directly into Remove-PiHoleDnsRecord' -Skip:(-not $script:ConfigAvailable) { + $removed = Get-PiHoleDnsRecord -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Hostname $script:AHostname | + Remove-PiHoleDnsRecord -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Restart $false -Confirm:$false + $removed | Format-List | Out-String | Write-Host + + $removed | Should -Not -BeNullOrEmpty + $removed.Status | Should -Be 'Removed' + + $hosts = (Get-PiHoleConfig -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl).Dns.Hosts + $hosts | Should -Not -Contain "$script:AIPv4 $script:AHostname" + + # Recreate it so AfterAll's cleanup (and other tests, if re-run) have a consistent state + Add-PiHoleConfigArrayItem -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Element 'dns/hosts' -Value "$script:AIPv4 $script:AHostname" -Restart $false | Out-Null + } + + It 'errors when given a bad password' -Skip:(-not $script:ConfigAvailable) { + $result = Get-PiHoleDnsRecord -PiHoleServer $script:PiHoleServer -Password 'definitely-not-the-real-token' -IgnoreSsl $script:PiHoleIgnoreSsl -ErrorVariable errOut -ErrorAction SilentlyContinue + + $errOut | Should -Not -BeNullOrEmpty + } +} diff --git a/tests/DnsControl/Remove-PiHoleDnsRecord.Integration.Tests.ps1 b/tests/DnsControl/Remove-PiHoleDnsRecord.Integration.Tests.ps1 index e8b9a0e..2845ae3 100644 --- a/tests/DnsControl/Remove-PiHoleDnsRecord.Integration.Tests.ps1 +++ b/tests/DnsControl/Remove-PiHoleDnsRecord.Integration.Tests.ps1 @@ -77,6 +77,23 @@ Describe 'Remove-PiHoleDnsRecord (Integration)' -Tag 'Integration' { Remove-PiHoleConfigArrayItem -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Element 'dns/hosts' -Value "$script:AIPv4 $script:AHostname" -Restart $false -Confirm:$false | Out-Null } + It 'accepts multiple records piped from Get-PiHoleDnsRecord in a single call' -Skip:(-not $script:ConfigAvailable) { + Add-PiHoleConfigArrayItem -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Element 'dns/hosts' -Value "$script:AIPv4 $script:AHostname" -Restart $false | Out-Null + Add-PiHoleConfigArrayItem -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Element 'dns/cnameRecords' -Value "$script:CnameHostname,$script:CnameTarget,$script:CnameTtl" -Restart $false | Out-Null + + $results = Get-PiHoleDnsRecord -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl | + Where-Object { $_.Hostname -in @($script:AHostname, $script:CnameHostname) } | + Remove-PiHoleDnsRecord -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Restart $false -Confirm:$false + $results | Format-Table | Out-String | Write-Host + + @($results).Count | Should -Be 2 + $results.Status | Should -Be @('Removed', 'Removed') + + $config = Get-PiHoleConfig -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl + $config.Dns.Hosts | Should -Not -Contain "$script:AIPv4 $script:AHostname" + $config.Dns.CnameRecords | Should -Not -Contain "$script:CnameHostname,$script:CnameTarget,$script:CnameTtl" + } + It 'errors when given a bad password' -Skip:(-not $script:ConfigAvailable) { $result = Remove-PiHoleDnsRecord -PiHoleServer $script:PiHoleServer -Password 'definitely-not-the-real-token' -IgnoreSsl $script:PiHoleIgnoreSsl -Type A -Hostname $script:AHostname -IPv4Address $script:AIPv4 -Restart $false -Confirm:$false -ErrorVariable errOut -ErrorAction SilentlyContinue diff --git a/tools/Update-ExampleOutput.ps1 b/tools/Update-ExampleOutput.ps1 index 3107407..cbbff6e 100644 --- a/tools/Update-ExampleOutput.ps1 +++ b/tools/Update-ExampleOutput.ps1 @@ -201,6 +201,11 @@ if ($appSudoEnabled) { -Invocation "Add-PiHoleDnsRecord -PiHoleServer `$PiHoleServer -Password `$Password -Type A -Hostname `"$docsDnsHostname`" -IPv4Address `"192.0.2.2`"" ` -Result (Add-PiHoleDnsRecord -PiHoleServer $PiHoleServer -Password $PiHoleToken -IgnoreSsl $PiHoleIgnoreSsl -Type A -Hostname $docsDnsHostname -IPv4Address '192.0.2.2' -Restart $false) + Add-Example -Category DnsControl -FunctionName 'Get-PiHoleDnsRecord' ` + -Invocation 'Get-PiHoleDnsRecord -PiHoleServer $PiHoleServer -Password $Password' ` + -Note 'Can be filtered with -Type and/or -Hostname, and piped directly into Remove-PiHoleDnsRecord.' ` + -Result (Get-PiHoleDnsRecord -PiHoleServer $PiHoleServer -Password $PiHoleToken -IgnoreSsl $PiHoleIgnoreSsl -Hostname $docsDnsHostname) + Add-Example -Category DnsControl -FunctionName 'Remove-PiHoleDnsRecord' ` -Invocation "Remove-PiHoleDnsRecord -PiHoleServer `$PiHoleServer -Password `$Password -Type A -Hostname `"$docsDnsHostname`" -IPv4Address `"192.0.2.2`"" ` -Result (Remove-PiHoleDnsRecord -PiHoleServer $PiHoleServer -Password $PiHoleToken -IgnoreSsl $PiHoleIgnoreSsl -Type A -Hostname $docsDnsHostname -IPv4Address '192.0.2.2' -Restart $false -Confirm:$false) @@ -219,6 +224,9 @@ else { Add-Example -Category DnsControl -FunctionName 'Add-PiHoleDnsRecord' ` -Invocation 'Add-PiHoleDnsRecord -PiHoleServer $PiHoleServer -Password $Password -Type A -Hostname "example.com" -IPv4Address "192.0.2.1"' ` -Note $appSudoNote -Skipped + Add-Example -Category DnsControl -FunctionName 'Get-PiHoleDnsRecord' ` + -Invocation 'Get-PiHoleDnsRecord -PiHoleServer $PiHoleServer -Password $Password' ` + -Note $appSudoNote -Skipped Add-Example -Category DnsControl -FunctionName 'Remove-PiHoleDnsRecord' ` -Invocation 'Remove-PiHoleDnsRecord -PiHoleServer $PiHoleServer -Password $Password -Type A -Hostname "example.com" -IPv4Address "192.0.2.1"' ` -Note $appSudoNote -Skipped From fd7871d866d66800027cb26ce367f7ca6d809ae6 Mon Sep 17 00:00:00 2001 From: Mike Madeja Date: Sun, 18 Oct 2026 19:26:36 -0500 Subject: [PATCH 4/7] test: extract shared setup/cleanup for DNS record integration tests SonarCloud flagged the BeforeAll/AfterAll blocks of the Get- and Remove-PiHoleDnsRecord integration tests as duplicated (8% duplication on new code, failing the quality gate). Move config loading and record cleanup into tests/DnsControl/DnsRecordTestHelpers.ps1 and use it from the Add, Get and Remove test files. Co-Authored-By: Claude Opus 5.5 --- .../Add-PiHoleDnsRecord.Integration.Tests.ps1 | 20 ++------ tests/DnsControl/DnsRecordTestHelpers.ps1 | 51 +++++++++++++++++++ .../Get-PiHoleDnsRecord.Integration.Tests.ps1 | 19 ++----- ...move-PiHoleDnsRecord.Integration.Tests.ps1 | 18 ++----- 4 files changed, 61 insertions(+), 47 deletions(-) create mode 100644 tests/DnsControl/DnsRecordTestHelpers.ps1 diff --git a/tests/DnsControl/Add-PiHoleDnsRecord.Integration.Tests.ps1 b/tests/DnsControl/Add-PiHoleDnsRecord.Integration.Tests.ps1 index a1a26d1..bcbb31c 100644 --- a/tests/DnsControl/Add-PiHoleDnsRecord.Integration.Tests.ps1 +++ b/tests/DnsControl/Add-PiHoleDnsRecord.Integration.Tests.ps1 @@ -15,6 +15,7 @@ $script:ConfigAvailable = Test-Path (Join-Path (Split-Path $PSScriptRoot -Parent Describe 'Add-PiHoleDnsRecord (Integration)' -Tag 'Integration' { BeforeAll { Import-Module .\PiHoleShell\PiHoleShell.psm1 -Force + . (Join-Path $PSScriptRoot 'DnsRecordTestHelpers.ps1') $script:AHostname = 'piholeshell-test-a.example.com' $script:AIPv4 = '192.0.2.201' @@ -24,26 +25,11 @@ Describe 'Add-PiHoleDnsRecord (Integration)' -Tag 'Integration' { $script:CnameTarget = 'piholeshell-test-a.example.com' $script:CnameTtl = 300 - $configPath = Join-Path (Split-Path $PSScriptRoot -Parent) 'IntegrationConfig.local.ps1' - if (Test-Path $configPath) { - . $configPath - $script:PiHoleServer = $PiHoleServer - $script:PiHoleToken = $PiHoleToken - $script:PiHoleIgnoreSsl = $PiHoleIgnoreSsl - - # Defensive cleanup in case a previous failed run left these behind - Remove-PiHoleConfigArrayItem -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Element 'dns/hosts' -Value "$script:AIPv4 $script:AHostname" -Restart $false -Confirm:$false -ErrorAction SilentlyContinue -WarningAction SilentlyContinue | Out-Null - Remove-PiHoleConfigArrayItem -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Element 'dns/hosts' -Value "$script:AaaaIPv6 $script:AaaaHostname" -Restart $false -Confirm:$false -ErrorAction SilentlyContinue -WarningAction SilentlyContinue | Out-Null - Remove-PiHoleConfigArrayItem -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Element 'dns/cnameRecords' -Value "$script:CnameHostname,$script:CnameTarget,$script:CnameTtl" -Restart $false -Confirm:$false -ErrorAction SilentlyContinue -WarningAction SilentlyContinue | Out-Null - } + Initialize-DnsRecordTest -Hosts "$script:AIPv4 $script:AHostname", "$script:AaaaIPv6 $script:AaaaHostname" -CnameRecords "$script:CnameHostname,$script:CnameTarget,$script:CnameTtl" } AfterAll { - if ($script:PiHoleServer) { - Remove-PiHoleConfigArrayItem -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Element 'dns/hosts' -Value "$script:AIPv4 $script:AHostname" -Restart $false -Confirm:$false -ErrorAction SilentlyContinue | Out-Null - Remove-PiHoleConfigArrayItem -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Element 'dns/hosts' -Value "$script:AaaaIPv6 $script:AaaaHostname" -Restart $false -Confirm:$false -ErrorAction SilentlyContinue | Out-Null - Remove-PiHoleConfigArrayItem -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Element 'dns/cnameRecords' -Value "$script:CnameHostname,$script:CnameTarget,$script:CnameTtl" -Restart $false -Confirm:$false -ErrorAction SilentlyContinue | Out-Null - } + Clear-DnsRecordTestData } It 'adds an A record and returns a formatted object' -Skip:(-not $script:ConfigAvailable) { diff --git a/tests/DnsControl/DnsRecordTestHelpers.ps1 b/tests/DnsControl/DnsRecordTestHelpers.ps1 new file mode 100644 index 0000000..2045727 --- /dev/null +++ b/tests/DnsControl/DnsRecordTestHelpers.ps1 @@ -0,0 +1,51 @@ +# Shared setup/cleanup for the *-PiHoleDnsRecord integration tests. Dot-source this from a +# Describe block's BeforeAll, then call Initialize-DnsRecordTest. + +function Initialize-DnsRecordTest { + # Loads tests/IntegrationConfig.local.ps1 into $script:PiHoleServer/PiHoleToken/PiHoleIgnoreSsl + # and removes any of the given test records a previous failed run left behind. Leaves + # $script:PiHoleServer unset if the config file is missing. + param ( + [string[]]$Hosts = @(), + [string[]]$CnameRecords = @() + ) + + $script:TestRecords = @{ Hosts = $Hosts; CnameRecords = $CnameRecords } + + $configPath = Join-Path (Split-Path $PSScriptRoot -Parent) 'IntegrationConfig.local.ps1' + if (-not (Test-Path $configPath)) { + return + } + + . $configPath + $script:PiHoleServer = $PiHoleServer + $script:PiHoleToken = $PiHoleToken + $script:PiHoleIgnoreSsl = $PiHoleIgnoreSsl + + Clear-DnsRecordTestData +} + +function Clear-DnsRecordTestData { + # Removes the records passed to Initialize-DnsRecordTest without complaining if they aren't + # there, so it's safe to call in AfterAll even after a test already removed them + if (-not $script:PiHoleServer) { + return + } + + $removeParams = @{ + PiHoleServer = $script:PiHoleServer + Password = $script:PiHoleToken + IgnoreSsl = $script:PiHoleIgnoreSsl + Restart = $false + Confirm = $false + ErrorAction = 'SilentlyContinue' + WarningAction = 'SilentlyContinue' + } + + foreach ($value in $script:TestRecords.Hosts) { + Remove-PiHoleConfigArrayItem @removeParams -Element 'dns/hosts' -Value $value | Out-Null + } + foreach ($value in $script:TestRecords.CnameRecords) { + Remove-PiHoleConfigArrayItem @removeParams -Element 'dns/cnameRecords' -Value $value | Out-Null + } +} diff --git a/tests/DnsControl/Get-PiHoleDnsRecord.Integration.Tests.ps1 b/tests/DnsControl/Get-PiHoleDnsRecord.Integration.Tests.ps1 index 637ef28..d93f18f 100644 --- a/tests/DnsControl/Get-PiHoleDnsRecord.Integration.Tests.ps1 +++ b/tests/DnsControl/Get-PiHoleDnsRecord.Integration.Tests.ps1 @@ -13,6 +13,7 @@ $script:ConfigAvailable = Test-Path (Join-Path (Split-Path $PSScriptRoot -Parent Describe 'Get-PiHoleDnsRecord (Integration)' -Tag 'Integration' { BeforeAll { Import-Module .\PiHoleShell\PiHoleShell.psm1 -Force + . (Join-Path $PSScriptRoot 'DnsRecordTestHelpers.ps1') $script:AHostname = 'piholeshell-test-get-a.example.com' $script:AIPv4 = '192.0.2.203' @@ -20,27 +21,15 @@ Describe 'Get-PiHoleDnsRecord (Integration)' -Tag 'Integration' { $script:CnameTarget = 'piholeshell-test-get-a.example.com' $script:CnameTtl = 300 - $configPath = Join-Path (Split-Path $PSScriptRoot -Parent) 'IntegrationConfig.local.ps1' - if (Test-Path $configPath) { - . $configPath - $script:PiHoleServer = $PiHoleServer - $script:PiHoleToken = $PiHoleToken - $script:PiHoleIgnoreSsl = $PiHoleIgnoreSsl - - # Defensive cleanup in case a previous failed run left these behind - Remove-PiHoleConfigArrayItem -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Element 'dns/hosts' -Value "$script:AIPv4 $script:AHostname" -Restart $false -Confirm:$false -ErrorAction SilentlyContinue -WarningAction SilentlyContinue | Out-Null - Remove-PiHoleConfigArrayItem -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Element 'dns/cnameRecords' -Value "$script:CnameHostname,$script:CnameTarget,$script:CnameTtl" -Restart $false -Confirm:$false -ErrorAction SilentlyContinue -WarningAction SilentlyContinue | Out-Null - + Initialize-DnsRecordTest -Hosts "$script:AIPv4 $script:AHostname" -CnameRecords "$script:CnameHostname,$script:CnameTarget,$script:CnameTtl" + if ($script:PiHoleServer) { Add-PiHoleConfigArrayItem -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Element 'dns/hosts' -Value "$script:AIPv4 $script:AHostname" -Restart $false | Out-Null Add-PiHoleConfigArrayItem -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Element 'dns/cnameRecords' -Value "$script:CnameHostname,$script:CnameTarget,$script:CnameTtl" -Restart $false | Out-Null } } AfterAll { - if ($script:PiHoleServer) { - Remove-PiHoleConfigArrayItem -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Element 'dns/hosts' -Value "$script:AIPv4 $script:AHostname" -Restart $false -Confirm:$false -ErrorAction SilentlyContinue | Out-Null - Remove-PiHoleConfigArrayItem -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Element 'dns/cnameRecords' -Value "$script:CnameHostname,$script:CnameTarget,$script:CnameTtl" -Restart $false -Confirm:$false -ErrorAction SilentlyContinue | Out-Null - } + Clear-DnsRecordTestData } It 'returns both the A and CNAME test records, correctly typed' -Skip:(-not $script:ConfigAvailable) { diff --git a/tests/DnsControl/Remove-PiHoleDnsRecord.Integration.Tests.ps1 b/tests/DnsControl/Remove-PiHoleDnsRecord.Integration.Tests.ps1 index 2845ae3..0a7177a 100644 --- a/tests/DnsControl/Remove-PiHoleDnsRecord.Integration.Tests.ps1 +++ b/tests/DnsControl/Remove-PiHoleDnsRecord.Integration.Tests.ps1 @@ -13,6 +13,7 @@ $script:ConfigAvailable = Test-Path (Join-Path (Split-Path $PSScriptRoot -Parent Describe 'Remove-PiHoleDnsRecord (Integration)' -Tag 'Integration' { BeforeAll { Import-Module .\PiHoleShell\PiHoleShell.psm1 -Force + . (Join-Path $PSScriptRoot 'DnsRecordTestHelpers.ps1') $script:AHostname = 'piholeshell-test-remove-a.example.com' $script:AIPv4 = '192.0.2.202' @@ -20,24 +21,11 @@ Describe 'Remove-PiHoleDnsRecord (Integration)' -Tag 'Integration' { $script:CnameTarget = 'piholeshell-test-remove-a.example.com' $script:CnameTtl = 300 - $configPath = Join-Path (Split-Path $PSScriptRoot -Parent) 'IntegrationConfig.local.ps1' - if (Test-Path $configPath) { - . $configPath - $script:PiHoleServer = $PiHoleServer - $script:PiHoleToken = $PiHoleToken - $script:PiHoleIgnoreSsl = $PiHoleIgnoreSsl - - # Defensive cleanup in case a previous failed run left these behind - Remove-PiHoleConfigArrayItem -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Element 'dns/hosts' -Value "$script:AIPv4 $script:AHostname" -Restart $false -Confirm:$false -ErrorAction SilentlyContinue -WarningAction SilentlyContinue | Out-Null - Remove-PiHoleConfigArrayItem -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Element 'dns/cnameRecords' -Value "$script:CnameHostname,$script:CnameTarget,$script:CnameTtl" -Restart $false -Confirm:$false -ErrorAction SilentlyContinue -WarningAction SilentlyContinue | Out-Null - } + Initialize-DnsRecordTest -Hosts "$script:AIPv4 $script:AHostname" -CnameRecords "$script:CnameHostname,$script:CnameTarget,$script:CnameTtl" } AfterAll { - if ($script:PiHoleServer) { - Remove-PiHoleConfigArrayItem -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Element 'dns/hosts' -Value "$script:AIPv4 $script:AHostname" -Restart $false -Confirm:$false -ErrorAction SilentlyContinue | Out-Null - Remove-PiHoleConfigArrayItem -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Element 'dns/cnameRecords' -Value "$script:CnameHostname,$script:CnameTarget,$script:CnameTtl" -Restart $false -Confirm:$false -ErrorAction SilentlyContinue | Out-Null - } + Clear-DnsRecordTestData } It 'removes an A record and returns a formatted object' -Skip:(-not $script:ConfigAvailable) { From b06a6ee5c84b18a54b2662a5366d14a6ebaaa88c Mon Sep 17 00:00:00 2001 From: Mike Madeja Date: Sun, 18 Oct 2026 21:21:51 -0500 Subject: [PATCH 5/7] chore: re-trigger SonarCloud analysis Co-Authored-By: Claude Opus 5.5 From 907e314b6a3cc036b27072bc243d9c5d227b739e Mon Sep 17 00:00:00 2001 From: Mike Madeja Date: Mon, 19 Oct 2026 17:00:56 -0500 Subject: [PATCH 6/7] feat: add Get-PiHoleAuthApp to generate an application password Wraps GET /api/auth/app. It only generates a password and its hash; the help explains how to activate it by setting webserver.api.app_pwhash with Set-PiHoleConfig. Checked against a live server: generating a password leaves the current app password and active sessions untouched. Co-Authored-By: Claude Opus 5.5 --- PiHoleShell/PiHoleShell.psd1 | Bin 7088 -> 7130 bytes PiHoleShell/PiHoleShell.psm1 | 2 +- .../Authentication/Get-PiHoleAuthApp.ps1 | 80 +++ README.md | 1 + docs/EXAMPLES.md | 518 +++++++++--------- .../Get-PiHoleAuthApp.Integration.Tests.ps1 | 63 +++ tools/Update-ExampleOutput.ps1 | 5 + 7 files changed, 416 insertions(+), 253 deletions(-) create mode 100644 PiHoleShell/Public/Authentication/Get-PiHoleAuthApp.ps1 create mode 100644 tests/Authentication/Get-PiHoleAuthApp.Integration.Tests.ps1 diff --git a/PiHoleShell/PiHoleShell.psd1 b/PiHoleShell/PiHoleShell.psd1 index bc9c9cb18c8d905d9ba2565b1df26aac550abafb..abd6f43b5333fc4636948347e97262d38c2e92af 100644 GIT binary patch delta 30 mcmdmBe#?BrD%QzuW7{JN09lp?o&W#< diff --git a/PiHoleShell/PiHoleShell.psm1 b/PiHoleShell/PiHoleShell.psm1 index d73e2ab..136606a 100644 --- a/PiHoleShell/PiHoleShell.psm1 +++ b/PiHoleShell/PiHoleShell.psm1 @@ -18,7 +18,7 @@ Export-ModuleMember -Function @( #Actions 'Update-PiHoleActionsGravity', 'Invoke-PiHoleFlushNetwork', 'Invoke-PiHoleFlushLogs', 'Restart-PiHoleDnsService' ` #Authentication - 'Remove-PiHoleCurrentAuthSession' , 'Get-PiHoleCurrentAuthSession', 'Remove-PiHoleAuthSession', 'Get-PiHoleAuthStatus', 'Get-PiHoleAuthTotp', ` + 'Remove-PiHoleCurrentAuthSession' , 'Get-PiHoleCurrentAuthSession', 'Remove-PiHoleAuthSession', 'Get-PiHoleAuthStatus', 'Get-PiHoleAuthTotp', 'Get-PiHoleAuthApp', ` #GroupManagement 'Get-PiHoleGroup', 'New-PiHoleGroup', 'Update-PiHoleGroup', 'Remove-PiHoleGroup', ` #DnsControl diff --git a/PiHoleShell/Public/Authentication/Get-PiHoleAuthApp.ps1 b/PiHoleShell/Public/Authentication/Get-PiHoleAuthApp.ps1 new file mode 100644 index 0000000..f931700 --- /dev/null +++ b/PiHoleShell/Public/Authentication/Get-PiHoleAuthApp.ps1 @@ -0,0 +1,80 @@ +function Get-PiHoleAuthApp { + <# +.SYNOPSIS +Generate a new application password + +.DESCRIPTION +Generates a new application password and its hash. The password is shown only once and cannot be +retrieved later, so store it somewhere safe. + +This only generates the password - it does not activate it, and your current app password keeps +working. To switch to the new one, set the returned Hash as webserver.api.app_pwhash, e.g. with +Set-PiHoleConfig (see the second example). Doing so replaces your current app password and ends +all active sessions. + +.PARAMETER PiHoleServer +The URL to the PiHole Server, for example "http://pihole.domain.com:8080", or "http://192.168.1.100" + +.PARAMETER Password +The API Password you generated from your PiHole server + +.PARAMETER IgnoreSsl +Set to $true to skip SSL certificate validation + +.PARAMETER RawOutput +This will dump the response instead of the formatted object + +.EXAMPLE +Get-PiHoleAuthApp -PiHoleServer "http://pihole.domain.com:8080" -Password "your-app-password" + +.EXAMPLE +$App = Get-PiHoleAuthApp -PiHoleServer "http://pihole.domain.com:8080" -Password "your-app-password" +Set-PiHoleConfig -PiHoleServer "http://pihole.domain.com:8080" -Password "your-app-password" -Settings @{ webserver = @{ api = @{ app_pwhash = $App.Hash } } } + +Generates a new app password and makes it the active one. From then on, use $App.Password. + #> + [CmdletBinding(HelpUri = 'https://ftl.pi-hole.net/master/docs/#get-/auth/app')] + [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingPlainTextForPassword", "Password")] + param ( + [Parameter(Mandatory = $true)] + [System.URI]$PiHoleServer, + [Parameter(Mandatory = $true)] + [string]$Password, + [bool]$IgnoreSsl = $false, + [bool]$RawOutput = $false + ) + try { + $Sid = Request-PiHoleAuth -PiHoleServer $PiHoleServer -Password $Password -IgnoreSsl $IgnoreSsl + + $Params = @{ + Headers = @{sid = $($Sid) } + Uri = "$($PiHoleServer.OriginalString)/api/auth/app" + Method = "Get" + SkipCertificateCheck = $IgnoreSsl + ContentType = "application/json" + } + + $Response = Invoke-RestMethod @Params + + if ($RawOutput) { + Write-Output $Response + } + else { + $Object = [PSCustomObject]@{ + Password = $Response.app.password + Hash = $Response.app.hash + } + Write-Output $Object + } + } + + catch { + Write-Error -Message (ConvertTo-PiHoleFriendlyErrorMessage -ErrorRecord $_) + } + + finally { + if ($Sid) { + Remove-PiHoleCurrentAuthSession -PiHoleServer $PiHoleServer -Sid $Sid -IgnoreSsl $IgnoreSsl + } + } +} diff --git a/README.md b/README.md index 311be4e..0fd780d 100644 --- a/README.md +++ b/README.md @@ -208,6 +208,7 @@ Session handling is automatic for every command above, but these are available f | Function | Description | |---|---| +| `Get-PiHoleAuthApp` | Generate a new application password | | `Get-PiHoleAuthStatus` | Check if authentication is required | | `Get-PiHoleAuthTotp` | Suggest new TOTP credentials | | `Get-PiHoleCurrentAuthSession` | List of all current sessions | diff --git a/docs/EXAMPLES.md b/docs/EXAMPLES.md index 4faea3f..ff4b693 100644 --- a/docs/EXAMPLES.md +++ b/docs/EXAMPLES.md @@ -151,9 +151,9 @@ New-PiHoleGroup -PiHoleServer $PiHoleServer -Password $Password -GroupName "PiHo Name : PiHoleShellDocsExampleGroup Comment : Example group Enabled : True -Id : 48 -DateAdded : 10/12/2026 6:38:10 PM -DateModified : 10/12/2026 6:38:10 PM +Id : 45 +DateAdded : 10/19/2026 4:33:10 PM +DateModified : 10/19/2026 4:33:10 PM ``` ### Get-PiHoleGroup @@ -195,9 +195,9 @@ DateModified : 9/30/2026 8:48:26 AM Name : PiHoleShellDocsExampleGroup Comment : Example group Enabled : True -Id : 48 -DateAdded : 10/12/2026 6:38:10 PM -DateModified : 10/12/2026 6:38:10 PM +Id : 45 +DateAdded : 10/19/2026 4:33:10 PM +DateModified : 10/19/2026 4:33:10 PM ``` ### Update-PiHoleGroup @@ -211,9 +211,9 @@ Update-PiHoleGroup -PiHoleServer $PiHoleServer -Password $Password -GroupName "P Name : PiHoleShellDocsExampleGroup Comment : Example group Enabled : False -Id : 48 -DateAdded : 10/12/2026 6:38:10 PM -DateModified : 10/12/2026 6:38:42 PM +Id : 45 +DateAdded : 10/19/2026 4:33:10 PM +DateModified : 10/19/2026 4:33:28 PM ``` ### Remove-PiHoleGroup @@ -242,9 +242,9 @@ Address : https://blocklistproject.github.io/Lists/alt-version/ransomware Comment : Example list Groups : {Default} Enabled : True -Id : 67 -DateAdded : 10/12/2026 6:39:53 PM -DateModified : 10/12/2026 6:39:53 PM +Id : 65 +DateAdded : 10/19/2026 4:34:05 PM +DateModified : 10/19/2026 4:34:05 PM Type : Block DateUpdated : Number : 0 @@ -270,7 +270,7 @@ DateAdded : 7/6/2025 2:20:13 AM DateModified : 7/6/2025 2:20:13 AM Type : block DateUpdated : 7/6/2025 2:20:13 AM -Number : 72526 +Number : 71493 InvalidDomains : 1 AbpEntries : 0 Status : 2 @@ -298,7 +298,7 @@ DateAdded : 7/6/2025 2:20:46 AM DateModified : 7/6/2025 2:20:46 AM Type : block DateUpdated : 7/6/2025 2:20:46 AM -Number : 178722 +Number : 185427 InvalidDomains : 0 AbpEntries : 0 Status : 2 @@ -346,9 +346,9 @@ Address : https://blocklistproject.github.io/Lists/alt-version/ransomware Comment : Example list Groups : {Default} Enabled : False -Id : 67 -DateAdded : 10/12/2026 6:39:53 PM -DateModified : 10/12/2026 6:40:54 PM +Id : 65 +DateAdded : 10/19/2026 4:34:05 PM +DateModified : 10/19/2026 4:34:39 PM Type : Block DateUpdated : Number : 0 @@ -374,8 +374,8 @@ Type : block Groups : {0} DateAdded : 7/6/2025 2:20:13 AM DateModified : 7/6/2025 2:20:13 AM -DateUpdated : 10/7/2026 4:41:49 PM -Number : 72526 +DateUpdated : 10/18/2026 10:04:20 PM +Number : 71493 InvalidDomains : 1 AbpEntries : 0 Status : 2 @@ -389,7 +389,7 @@ Type : block Groups : {0} DateAdded : 7/6/2025 2:20:40 AM DateModified : 7/6/2025 2:20:40 AM -DateUpdated : 7/6/2025 2:25:21 AM +DateUpdated : 10/17/2026 10:41:38 AM Number : 6540 InvalidDomains : 0 AbpEntries : 0 @@ -404,8 +404,8 @@ Type : block Groups : {0} DateAdded : 7/6/2025 2:20:46 AM DateModified : 7/6/2025 2:20:46 AM -DateUpdated : 10/10/2026 7:37:55 PM -Number : 178722 +DateUpdated : 10/19/2026 4:24:30 PM +Number : 185427 InvalidDomains : 0 AbpEntries : 0 Status : 2 @@ -419,7 +419,7 @@ Type : block Groups : {0} DateAdded : 7/6/2025 2:20:59 AM DateModified : 7/6/2025 2:20:59 AM -DateUpdated : 12/27/2025 9:28:21 PM +DateUpdated : 10/17/2026 10:41:52 AM Number : 42531 InvalidDomains : 0 AbpEntries : 0 @@ -434,7 +434,7 @@ Type : block Groups : {0} DateAdded : 7/6/2025 2:21:09 AM DateModified : 7/6/2025 2:21:09 AM -DateUpdated : 6/6/2026 11:13:26 PM +DateUpdated : 10/17/2026 10:41:55 AM Number : 2700 InvalidDomains : 0 AbpEntries : 0 @@ -473,9 +473,9 @@ Kind : Exact Comment : Example domain Groups : {Default} Enabled : True -Id : 18 -DateAdded : 10/12/2026 6:42:07 PM -DateModified : 10/12/2026 6:42:07 PM +Id : 1 +DateAdded : 10/19/2026 4:35:17 PM +DateModified : 10/19/2026 4:35:17 PM ``` ### Get-PiHoleDomain @@ -493,9 +493,9 @@ Kind : exact Comment : Example domain Groups : {Default} Enabled : True -Id : 18 -DateAdded : 10/12/2026 6:42:07 PM -DateModified : 10/12/2026 6:42:07 PM +Id : 1 +DateAdded : 10/19/2026 4:35:17 PM +DateModified : 10/19/2026 4:35:17 PM ``` ### Update-PiHoleDomain @@ -513,9 +513,9 @@ Kind : Exact Comment : Example domain Groups : {Default} Enabled : False -Id : 18 -DateAdded : 10/12/2026 6:42:07 PM -DateModified : 10/12/2026 6:43:09 PM +Id : 1 +DateAdded : 10/19/2026 4:35:17 PM +DateModified : 10/19/2026 4:35:51 PM ``` ### Remove-PiHoleDomain @@ -546,9 +546,9 @@ Client : 192.168.99.99 Name : Comment : Example client Groups : {Default} -Id : 20 -DateAdded : 10/12/2026 6:44:07 PM -DateModified : 10/12/2026 6:44:07 PM +Id : 1 +DateAdded : 10/19/2026 4:36:21 PM +DateModified : 10/19/2026 4:36:21 PM ``` ### Get-PiHoleClient @@ -563,9 +563,9 @@ Client : 192.168.99.99 Name : Comment : Example client Groups : {Default} -Id : 20 -DateAdded : 10/12/2026 6:44:07 PM -DateModified : 10/12/2026 6:44:07 PM +Id : 1 +DateAdded : 10/19/2026 4:36:21 PM +DateModified : 10/19/2026 4:36:21 PM ``` ### Get-PiHoleClientSuggestion @@ -576,16 +576,22 @@ Get-PiHoleClientSuggestion -PiHoleServer $PiHoleServer -Password $Password ``` -HwAddr : ip-127.0.0.1 -MacVendor : -LastQuery : 10/12/2026 6:37:42 PM -Addresses : 127.0.0.1 +HwAddr : 00:00:00:00:00:00 +MacVendor : virtual interface +LastQuery : 10/19/2026 4:32:55 PM +Addresses : 127.0.0.1,::1,0.0.0.0 Names : localhost HwAddr : 74:56:3c:bb:f4:0b MacVendor : Giga-Byte Technology Co.,Ltd. -LastQuery : 10/12/2026 6:31:26 PM +LastQuery : 10/18/2026 11:01:25 PM Addresses : 192.168.1.162 +Names : + +HwAddr : b8:27:eb:11:a4:d5 +MacVendor : Raspberry Pi Foundation +LastQuery : 12/31/1969 6:00:00 PM +Addresses : 192.168.1.248,fe80::ba27:ebff:fe11:a4d5 Names : ``` @@ -601,9 +607,9 @@ Client : 192.168.99.99 Name : Comment : Updated comment Groups : {Default} -Id : 20 -DateAdded : 10/12/2026 6:44:07 PM -DateModified : 10/12/2026 6:45:19 PM +Id : 1 +DateAdded : 10/19/2026 4:36:21 PM +DateModified : 10/19/2026 4:37:00 PM ``` ### Remove-PiHoleClient @@ -628,18 +634,18 @@ Get-PiHoleStatsSummary -PiHoleServer $PiHoleServer -Password $Password ``` -Total : 41 -Blocked : 9 -PercentBlocked : 21.9512195587158 -UniqueDomains : 16 -Forwarded : 24 -Cached : 8 +Total : 311 +Blocked : 88 +PercentBlocked : 28.2958202362061 +UniqueDomains : 22 +Forwarded : 37 +Cached : 186 Frequency : 0 -Types : @{A=16; AAAA=17; ANY=0; SRV=0; SOA=0; PTR=8; TXT=0; NAPTR=0; MX=0; DS=0; RRSIG=0; DNSKEY=0; NS=0; SVCB=0; HTTPS=0; OTHER=0} -Status : @{Unknown=0; Gravity=9; Forwarded=24; Cache=8; Regex=0; DenyList=0; ExternalBlockedIp=0; ExternalBlockedNull=0; ExternalBlockedNxra=0; GravityCname=0; RegexCname=0; DenyListCname=0; Retired=0; RetiredDnssec=0; InProgress=0; Dbbusy=0; SpecialDomain=0; CacheStale=0; ExternalBlockedEde15=0} -Replies : @{Unknown=4; Nodata=3; Nxdomain=2; Cname=0; Ip=26; Domain=6; Rrname=0; ServFail=0; Refused=0; Notimp=0; Other=0; Dnssec=0; None=0; Blob=0} +Types : @{A=137; AAAA=137; ANY=0; SRV=0; SOA=0; PTR=37; TXT=0; NAPTR=0; MX=0; DS=0; RRSIG=0; DNSKEY=0; NS=0; SVCB=0; HTTPS=0; OTHER=0} +Status : @{Unknown=0; Gravity=88; Forwarded=37; Cache=154; Regex=0; DenyList=0; ExternalBlockedIp=0; ExternalBlockedNull=0; ExternalBlockedNxra=0; GravityCname=0; RegexCname=0; DenyListCname=0; Retired=0; RetiredDnssec=0; InProgress=0; Dbbusy=0; SpecialDomain=0; CacheStale=32; ExternalBlockedEde15=0} +Replies : @{Unknown=9; Nodata=16; Nxdomain=6; Cname=0; Ip=249; Domain=31; Rrname=0; ServFail=0; Refused=0; Notimp=0; Other=0; Dnssec=0; None=0; Blob=0} Clients : @{Active=2; Total=2} -Gravity : @{DomainsBeingBlocked=560453; LastUpdate=1791845621} +Gravity : @{DomainsBeingBlocked=585338; LastUpdate=1792445332} ``` ### Get-PiHoleStatsRecentBlocked @@ -662,10 +668,10 @@ Get-PiHoleStatsQueryType -PiHoleServer $PiHoleServer -Password $Password ``` Type : A -Count : 16 +Count : 137 Type : AAAA -Count : 17 +Count : 137 Type : ANY Count : 0 @@ -687,20 +693,20 @@ Get-PiHoleStatsTopDomain -PiHoleServer $PiHoleServer -Password $Password ``` -Domain : wikipedia.org -Count : 4 - -Domain : bbc.com -Count : 4 +Domain : cloudflare.com +Count : 22 -Domain : mozilla.org -Count : 3 +Domain : 1.0.0.127.in-addr.arpa +Count : 21 Domain : apple.com -Count : 3 +Count : 20 -Domain : github.com -Count : 3 +Domain : reddit.com +Count : 20 + +Domain : wikipedia.org +Count : 18 _(showing 5 of 10 results)_ ``` @@ -715,11 +721,11 @@ Get-PiHoleStatsTopClient -PiHoleServer $PiHoleServer -Password $Password IP : 192.168.1.162 Name : -Count : 33 +Count : 274 IP : 127.0.0.1 Name : localhost -Count : 8 +Count : 37 ``` ### Get-PiHoleStatsUpstream @@ -730,9 +736,9 @@ Get-PiHoleStatsUpstream -PiHoleServer $PiHoleServer -Password $Password ``` -TotalQueries : 41 -ForwardedQueries : 24 -Upstreams : {@{Ip=blocklist; Name=blocklist; Port=-1; Count=9; ResponseTime=0; Variance=0}, @{Ip=cache; Name=cache; Port=-1; Count=8; ResponseTime=0; Variance=0}, @{Ip=8.8.4.4; Name=dns.google; Port=53; Count=22; ResponseTime=0; Variance=0}, @{Ip=8.8.8.8; Name=dns.google; Port=53; Count=2; ResponseTime=0; Variance=0}} +TotalQueries : 311 +ForwardedQueries : 37 +Upstreams : {@{Ip=blocklist; Name=blocklist; Port=-1; Count=88; ResponseTime=0; Variance=0}, @{Ip=cache; Name=cache; Port=-1; Count=186; ResponseTime=0; Variance=0}, @{Ip=8.8.8.8; Name=; Port=53; Count=32; ResponseTime=0; Variance=0}, @{Ip=8.8.4.4; Name=; Port=53; Count=5; ResponseTime=0; Variance=0}} ``` ### Get-PiHoleStatsQuerySuggestions @@ -743,10 +749,10 @@ Get-PiHoleStatsQuerySuggestions -PiHoleServer $PiHoleServer -Password $Password ``` -Domain : {wikipedia.org, bbc.com, mozilla.org, apple.com…} +Domain : {cloudflare.com, 1.0.0.127.in-addr.arpa, apple.com, reddit.com…} ClientIp : {192.168.1.162, 127.0.0.1} ClientName : {localhost} -Upstream : {blocklist, cache, 8.8.4.4#53 (dns.google), 8.8.8.8#53 (dns.google)…} +Upstream : {blocklist, cache, 8.8.8.8#53, 8.8.4.4#53…} Type : {A, AAAA, ANY, SRV…} Status : {UNKNOWN, GRAVITY, FORWARDED, CACHE…} Reply : {UNKNOWN, NODATA, NXDOMAIN, CNAME…} @@ -763,10 +769,10 @@ Get-PiHoleStatsDatabaseSummary -PiHoleServer $PiHoleServer -Password $Password ``` -SumQueries : 41 -SumBlocked : 9 -PercentBlocked : 21.9512195587158 -TotalClients : 3 +SumQueries : 10 +SumBlocked : 0 +PercentBlocked : 0 +TotalClients : 1 ``` ### Get-PiHoleStatsDatabaseQueryType @@ -780,7 +786,7 @@ Get-PiHoleStatsDatabaseQueryType -PiHoleServer $PiHoleServer -Password $Password ``` Type : A -Count : 17 +Count : 0 Type : AAAA Count : 0 @@ -792,7 +798,7 @@ Type : SRV Count : 0 Type : SOA -Count : 8 +Count : 0 _(showing 5 of 16 results)_ ``` @@ -807,22 +813,11 @@ Get-PiHoleStatsDatabaseTopDomain -PiHoleServer $PiHoleServer -Password $Password ``` -Domain : bbc.com -Count : 4 - -Domain : wikipedia.org -Count : 4 - -Domain : mozilla.org -Count : 3 - -Domain : stackoverflow.com -Count : 3 +Domain : 1.0.0.127.in-addr.arpa +Count : 9 -Domain : apple.com -Count : 3 - -_(showing 5 of 10 results)_ +Domain : 162.1.168.192.in-addr.arpa +Count : 1 ``` ### Get-PiHoleStatsDatabaseTopClient @@ -835,17 +830,9 @@ Get-PiHoleStatsDatabaseTopClient -PiHoleServer $PiHoleServer -Password $Password ``` -IP : 192.168.1.162 -Name : -Count : 24 - IP : 127.0.0.1 Name : localhost -Count : 5 - -IP : 127.0.0.1 -Name : -Count : 3 +Count : 10 ``` ### Get-PiHoleStatsDatabaseUpstream @@ -858,9 +845,9 @@ Get-PiHoleStatsDatabaseUpstream -PiHoleServer $PiHoleServer -Password $Password ``` -TotalQueries : 41 -ForwardedQueries : 24 -Upstreams : {@{Ip=1; Name=; Port=-1; Count=22; ResponseTime=0; Variance=0}, @{Ip=2; Name=; Port=-1; Count=2; ResponseTime=0; Variance=0}, @{Ip=cache; Name=cache; Port=-1; Count=8; ResponseTime=0; Variance=0}, @{Ip=blocklist; Name=blocklist; Port=-1; Count=9; ResponseTime=0; Variance=0}} +TotalQueries : 10 +ForwardedQueries : 0 +Upstreams : {@{Ip=cache; Name=cache; Port=-1; Count=10; ResponseTime=0; Variance=0}, @{Ip=blocklist; Name=blocklist; Port=-1; Count=0; ResponseTime=0; Variance=0}} ``` ### Get-PiHoleQuery @@ -873,67 +860,67 @@ Get-PiHoleQuery -PiHoleServer $PiHoleServer -Password $Password -Length 5 ``` -Id : 40 -Time : 10/12/2026 6:37:42 PM +Id : 688 +Time : 10/19/2026 4:32:56 PM Type : PTR -Domain : 8.8.8.8.in-addr.arpa +Domain : 1.0.0.127.in-addr.arpa Cname : -Status : FORWARDED +Status : CACHE Client : @{Ip=127.0.0.1; Name=localhost} Dnssec : UNKNOWN -Reply : @{Type=DOMAIN; Time=0.0698070526123047} +Reply : @{Type=DOMAIN; Time=0.00135612487792969} ListId : -Upstream : 8.8.8.8#53 +Upstream : Ede : @{Code=-1; Text=} -Id : 39 -Time : 10/12/2026 6:37:41 PM +Id : 687 +Time : 10/19/2026 4:32:56 PM Type : PTR -Domain : 4.4.8.8.in-addr.arpa +Domain : 162.1.168.192.in-addr.arpa Cname : -Status : FORWARDED +Status : CACHE Client : @{Ip=127.0.0.1; Name=localhost} Dnssec : UNKNOWN -Reply : @{Type=DOMAIN; Time=0.0369069576263428} +Reply : @{Type=NXDOMAIN; Time=0.0235791206359863} ListId : -Upstream : 8.8.8.8#53 +Upstream : Ede : @{Code=-1; Text=} -Id : 38 -Time : 10/12/2026 6:37:41 PM +Id : 686 +Time : 10/19/2026 4:00:01 PM Type : PTR Domain : 1.0.0.127.in-addr.arpa Cname : Status : CACHE Client : @{Ip=127.0.0.1; Name=localhost} Dnssec : UNKNOWN -Reply : @{Type=DOMAIN; Time=0.00117111206054688} +Reply : @{Type=DOMAIN; Time=0.000164031982421875} ListId : Upstream : Ede : @{Code=-1; Text=} -Id : 37 -Time : 10/12/2026 6:37:41 PM +Id : 685 +Time : 10/19/2026 3:00:01 PM Type : PTR -Domain : 162.1.168.192.in-addr.arpa +Domain : 1.0.0.127.in-addr.arpa Cname : Status : CACHE Client : @{Ip=127.0.0.1; Name=localhost} Dnssec : UNKNOWN -Reply : @{Type=NXDOMAIN; Time=0.0176899433135986} +Reply : @{Type=DOMAIN; Time=0.000163078308105469} ListId : Upstream : Ede : @{Code=-1; Text=} -Id : 36 -Time : 10/12/2026 6:31:28 PM +Id : 684 +Time : 10/19/2026 2:00:00 PM Type : PTR Domain : 1.0.0.127.in-addr.arpa Cname : Status : CACHE Client : @{Ip=127.0.0.1; Name=localhost} Dnssec : UNKNOWN -Reply : @{Type=DOMAIN; Time=0.00136184692382812} +Reply : @{Type=DOMAIN; Time=0.000160932540893555} ListId : Upstream : Ede : @{Code=-1; Text=} @@ -1048,20 +1035,20 @@ CpuPercent : 0 MemoryPercent : 0 ActiveClients : 2 Blocking : enabled -Cache : @{Size=10000; Inserted=30; Evicted=0} +Cache : @{Size=10000; Inserted=2; Evicted=0} Config : @{DhcpActive=False; DhcpStart=; DhcpEnd=; DhcpIpv6=False; DnsDnssec=False; DnsDomain=lan; DnsNumUpstreams=2; DnsPort=53; DnsrevServerAactive=False; PrivacyLevel=0} -GravitySize : 560453 +GravitySize : 585338 HostModel : Raspberry Pi Zero W Rev 1.1 IFace : @{v4=; v6=} NodeName : dns3.localdomain -Pid : 388 -Queries : @{Total=37; Blocked=9; PercentBlocked=24.3243236541748; QueryFrequency=0} +Pid : 392 +Queries : @{Total=309; Blocked=88; PercentBlocked=28.4789638519287; QueryFrequency=0} RecentBlocked : googleadservices.com -Sensors : @{CpuTemp=43.312; HotLimit=60; Unit=C} -System : @{Uptime=156002; Memory=; Procs=74; Cpu=; Ftl=} -TopBlocked : doubleclick.net +Sensors : @{CpuTemp=40.622; HotLimit=60; Unit=C} +System : @{Uptime=169898; Memory=; Procs=73; Cpu=; Ftl=} +TopBlocked : googleadservices.com TopClient : 192.168.1.162 -TopDomain : bbc.com +TopDomain : cloudflare.com Version : @{Core=; Web=; Ftl=; Docker=} ``` @@ -1098,11 +1085,11 @@ Get-PiHoleInfoSystem -PiHoleServer $PiHoleServer -Password $Password ``` -Uptime : 156022 +Uptime : 169908 Memory : @{Ram=; Swap=} -Procs : 74 -Cpu : @{NumProcessors=1; PercentCpu=100.099998474121; Load=} -Ftl : @{PercentMemory=2.43389201164246; PercentCpu=99.3000030517578} +Procs : 72 +Cpu : @{NumProcessors=1; PercentCpu=97.0999984741211; Load=} +Ftl : @{PercentMemory=2.38621687889099; PercentCpu=96.3000030517578} ``` ### Get-PiHoleInfoFtl @@ -1113,16 +1100,16 @@ Get-PiHoleInfoFtl -PiHoleServer $PiHoleServer -Password $Password ``` -Database : @{Gravity=560453; Antigravity=0; Groups=4; Lists=14; Clients=0; Domains=; Regex=} +Database : @{Gravity=585338; Antigravity=0; Groups=4; Lists=14; Clients=0; Domains=; Regex=} PrivacyLevel : 0 QueryFrequency : 0 Clients : @{Total=2; Active=2} -Pid : 388 -Uptime : 979769.972744 -PercentMemory : 2.42485022544861 -PercentCpu : 99.1999969482422 +Pid : 392 +Uptime : 62980865.090079 +PercentMemory : 2.38621687889099 +PercentCpu : 96.3000030517578 AllowDestructive : True -Dnsmasq : @{DnsCacheInserted=30; DnsCacheLiveFreed=0; DnsQueriesForwarded=22; DnsAuthAnswered=0; DnsLocalAnswered=15; DnsStaleAnswered=0; DnsUnanswered=0; DnssecMaxCryptoUse=0; DnssecMaxSigFail=0; DnssecMaxWork=0; Bootp=0; Pxe=0; DhcpAck=0; DhcpDecline=0; DhcpDiscover=0; DhcpInform=0; DhcpNak=0; DhcpOffer=0; DhcpRelease=0; DhcpRequest=0; Noanswer=0; LeasesAllocated4=0; LeasesPruned4=0; LeasesAllocated6=0; LeasesPruned6=0; TcpConnections=0; DhcpLeasequery=0; DhcpLeaseUnassigned=0; DhcpLeaseActve=0; DhcpLeaseUnknown=0} +Dnsmasq : @{DnsCacheInserted=2; DnsCacheLiveFreed=0; DnsQueriesForwarded=2; DnsAuthAnswered=0; DnsLocalAnswered=25; DnsStaleAnswered=0; DnsUnanswered=0; DnssecMaxCryptoUse=0; DnssecMaxSigFail=0; DnssecMaxWork=0; Bootp=0; Pxe=0; DhcpAck=0; DhcpDecline=0; DhcpDiscover=0; DhcpInform=0; DhcpNak=0; DhcpOffer=0; DhcpRelease=0; DhcpRequest=0; Noanswer=0; LeasesAllocated4=0; LeasesPruned4=0; LeasesAllocated6=0; LeasesPruned6=0; TcpConnections=0; DhcpLeasequery=0; DhcpLeaseUnassigned=0; DhcpLeaseActve=0; DhcpLeaseUnknown=0} ``` ### Get-PiHoleInfoSensors @@ -1134,7 +1121,7 @@ Get-PiHoleInfoSensors -PiHoleServer $PiHoleServer -Password $Password ``` List : {@{Name=cpu_thermal; Path=hwmon0; Source=devices/virtual/thermal/thermal_zone0; Temps=}, @{Name=rpi_volt; Path=hwmon1; Source=devices/platform/soc/soc:firmware/raspberrypi-hwmon; Temps=}} -CpuTemp : 43.312 +CpuTemp : 40.622 HotLimit : 60 Unit : C ``` @@ -1151,14 +1138,14 @@ Size : 13983744 Type : Regular file Mode : rw-r----- AccessTime : 6/25/2025 12:32:44 AM -ModifiedTime : 10/12/2026 6:19:17 PM -ChangeTime : 10/12/2026 6:19:17 PM +ModifiedTime : 10/19/2026 2:02:00 PM +ChangeTime : 10/19/2026 2:02:00 PM Owner : @{User=; Group=} -Queries : 37 -EarliestTimestamp : 10/11/2026 6:30:00 PM -QueriesDisk : 37 -EarliestTimestampDisk : -SqliteVersion : 3.53.1 +Queries : 309 +EarliestTimestamp : 10/18/2026 4:30:00 PM +QueriesDisk : 336 +EarliestTimestampDisk : 10/16/2026 11:00:01 PM +SqliteVersion : 3.53.3 ``` ### Get-PiHoleInfoVersion @@ -1226,10 +1213,16 @@ Get-PiHoleInfoMessage -PiHoleServer $PiHoleServer -Password $Password ``` Id : 1 -Timestamp : 10/12/2026 6:34:19 PM +Timestamp : 10/18/2026 11:02:08 PM Type : LOAD -Plain : Long-term load (15min avg) larger than number of processors: 1.9 > 1 -Html : Long-term load (15min avg) larger than number of processors: 1.9 > 1
This may slow down DNS resolution and can cause bottlenecks. +Plain : Long-term load (15min avg) larger than number of processors: 1.0 > 1 +Html : Long-term load (15min avg) larger than number of processors: 1.0 > 1
This may slow down DNS resolution and can cause bottlenecks. + +Id : 2 +Timestamp : 10/19/2026 4:22:33 PM +Type : LIST +Plain : List with ID 53 (https://v.firebog.net/hosts/AdguardDNS.txt) was inaccessible during last gravity run +Html : List with ID 53 (https://v.firebog.net/hosts/AdguardDNS.txt) was inaccessible during last gravity run ``` ### Get-PiHoleInfoMessageCount @@ -1240,7 +1233,7 @@ Get-PiHoleInfoMessageCount -PiHoleServer $PiHoleServer -Password $Password ``` -Count : 1 +Count : 2 ``` ### Remove-PiHoleInfoMessage @@ -1264,9 +1257,9 @@ Get-PiHoleLogWebserver -PiHoleServer $PiHoleServer -Password $Password ``` -Log : {@{Timestamp=10/12/2026 6:19:19 PM; Message=Initializing HTTP server on ports "8089,8489s"; Priority=}, @{Timestamp=10/12/2026 6:33:39 PM; Message=ACCESS: 192.168.1.162 - - [12/Oct/2026:23:33:38 +0000] "PATCH /api/config?restart=false HTTP/1.1" 200 4589 - Mozilla/5.0 (Windows NT 10.0; Microsoft Windows 10.0.26200; en-US) PowerShell/7.6.6; Priority=}, @{Timestamp=10/12/2026 6:33:39 PM; Message=ACCESS: 192.168.1.162 - - [12/Oct/2026:23:33:38 +0000] "DELETE /api/auth HTTP/1.1" 204 558 - Mozilla/5.0 (Windows NT 10.0; Microsoft Windows 10.0.26200; en-US) PowerShell/7.6.6; Priority=}, @{Timestamp=10/12/2026 6:33:42 PM; Message=ACCESS: 192.168.1.162 - - [12/Oct/2026:23:33:33 +0000] "POST /api/auth HTTP/1.1" 200 808 - Mozilla/5.0 (Windows NT 10.0; Microsoft Windows 10.0.26200; en-US) PowerShell/7.6.6; Priority=}…} -NextID : 7 -Pid : 388 +Log : {@{Timestamp=10/18/2026 11:02:09 PM; Message=Initializing HTTP server on ports "8089,8489s"; Priority=}, @{Timestamp=10/19/2026 4:30:47 PM; Message=ACCESS: 192.168.1.162 - - [19/Oct/2026:21:30:46 +0000] "PATCH /api/config?restart=false HTTP/1.1" 200 4589 - Mozilla/5.0 (Windows NT 10.0; Microsoft Windows 10.0.26200; en-US) PowerShell/7.6.6; Priority=}, @{Timestamp=10/19/2026 4:30:47 PM; Message=ACCESS: 192.168.1.162 - - [19/Oct/2026:21:30:46 +0000] "DELETE /api/auth HTTP/1.1" 204 624 - Mozilla/5.0 (Windows NT 10.0; Microsoft Windows 10.0.26200; en-US) PowerShell/7.6.6; Priority=}, @{Timestamp=10/19/2026 4:30:51 PM; Message=ACCESS: 192.168.1.162 - - [19/Oct/2026:21:30:47 +0000] "POST /api/auth HTTP/1.1" 200 808 - Mozilla/5.0 (Windows NT 10.0; Microsoft Windows 10.0.26200; en-US) PowerShell/7.6.6; Priority=}} +NextID : 4 +Pid : 392 File : /var/log/pihole/webserver.log ``` @@ -1278,9 +1271,9 @@ Get-PiHoleLogDnsmasq -PiHoleServer $PiHoleServer -Password $Password ``` -Log : {@{Timestamp=10/12/2026 6:19:19 PM; Message=started, version pi-hole-v2.93 cachesize 10000; Priority=}, @{Timestamp=10/12/2026 6:19:19 PM; Message=DNS service limited to local subnets; Priority=}, @{Timestamp=10/12/2026 6:19:19 PM; Message=compile time options: IPv6 GNU-getopt no-DBus no-UBus no-i18n IDN2 DHCP DHCPv6 Lua TFTP no-conntrack ipset no-nftset auth DNSSEC loop-detect inotify dumpfile; Priority=}, @{Timestamp=10/12/2026 6:19:19 PM; Message=using nameserver 8.8.8.8#53; Priority=}…} -NextID : 39 -Pid : 388 +Log : {@{Timestamp=10/18/2026 11:02:09 PM; Message=started, version pi-hole-v2.93+30 cachesize 10000; Priority=}, @{Timestamp=10/18/2026 11:02:09 PM; Message=DNS service limited to local subnets; Priority=}, @{Timestamp=10/18/2026 11:02:09 PM; Message=compile time options: IPv6 GNU-getopt no-DBus no-UBus no-i18n IDN2 DHCP DHCPv6 Lua TFTP no-conntrack ipset no-nftset auth DNSSEC loop-detect inotify dumpfile; Priority=}, @{Timestamp=10/18/2026 11:02:09 PM; Message=using nameserver 8.8.8.8#53; Priority=}…} +NextID : 27 +Pid : 392 File : /var/log/pihole/pihole.log ``` @@ -1292,9 +1285,9 @@ Get-PiHoleLogFtl -PiHoleServer $PiHoleServer -Password $Password ``` -Log : {@{Timestamp=10/12/2026 6:19:18 PM; Message=PID of FTL process: 388; Priority=INFO}, @{Timestamp=10/12/2026 6:19:18 PM; Message=listening on 0.0.0.0 port 53; Priority=INFO}, @{Timestamp=10/12/2026 6:19:18 PM; Message=listening on :: port 53; Priority=INFO}, @{Timestamp=10/12/2026 6:19:18 PM; Message=Database version is 22; Priority=INFO}…} -NextID : 237 -Pid : 388 +Log : {@{Timestamp=10/18/2026 11:02:07 PM; Message=PID of FTL process: 392; Priority=INFO}, @{Timestamp=10/18/2026 11:02:07 PM; Message=listening on 0.0.0.0 port 53; Priority=INFO}, @{Timestamp=10/18/2026 11:02:07 PM; Message=listening on :: port 53; Priority=INFO}, @{Timestamp=10/18/2026 11:02:07 PM; Message=Database version is 22; Priority=INFO}…} +NextID : 180 +Pid : 392 File : /var/log/pihole/FTL.log ``` @@ -1335,31 +1328,31 @@ Get-PiHoleHistory -PiHoleServer $PiHoleServer -Password $Password ``` -Timestamp : 10/11/2026 6:45:00 PM +Timestamp : 10/18/2026 4:35:00 PM Total : 0 Cached : 0 Blocked : 0 Forwarded : 0 -Timestamp : 10/11/2026 6:55:00 PM +Timestamp : 10/18/2026 4:45:00 PM Total : 0 Cached : 0 Blocked : 0 Forwarded : 0 -Timestamp : 10/11/2026 7:05:00 PM +Timestamp : 10/18/2026 4:55:00 PM Total : 0 Cached : 0 Blocked : 0 Forwarded : 0 -Timestamp : 10/11/2026 7:15:00 PM +Timestamp : 10/18/2026 5:05:00 PM Total : 0 Cached : 0 Blocked : 0 Forwarded : 0 -Timestamp : 10/11/2026 7:25:00 PM +Timestamp : 10/18/2026 5:15:00 PM Total : 0 Cached : 0 Blocked : 0 @@ -1376,19 +1369,19 @@ Get-PiHoleHistoryClient -PiHoleServer $PiHoleServer -Password $Password ``` -Timestamp : 10/11/2026 6:45:00 PM +Timestamp : 10/18/2026 4:35:00 PM Clients : {@{IP=192.168.1.162; Name=; Count=0}, @{IP=127.0.0.1; Name=localhost; Count=0}, @{IP=others; Name=; Count=0}} -Timestamp : 10/11/2026 6:55:00 PM +Timestamp : 10/18/2026 4:45:00 PM Clients : {@{IP=192.168.1.162; Name=; Count=0}, @{IP=127.0.0.1; Name=localhost; Count=0}, @{IP=others; Name=; Count=0}} -Timestamp : 10/11/2026 7:05:00 PM +Timestamp : 10/18/2026 4:55:00 PM Clients : {@{IP=192.168.1.162; Name=; Count=0}, @{IP=127.0.0.1; Name=localhost; Count=0}, @{IP=others; Name=; Count=0}} -Timestamp : 10/11/2026 7:15:00 PM +Timestamp : 10/18/2026 5:05:00 PM Clients : {@{IP=192.168.1.162; Name=; Count=0}, @{IP=127.0.0.1; Name=localhost; Count=0}, @{IP=others; Name=; Count=0}} -Timestamp : 10/11/2026 7:25:00 PM +Timestamp : 10/18/2026 5:15:00 PM Clients : {@{IP=192.168.1.162; Name=; Count=0}, @{IP=127.0.0.1; Name=localhost; Count=0}, @{IP=others; Name=; Count=0}} _(showing 5 of 145 results)_ @@ -1404,11 +1397,37 @@ Get-PiHoleHistoryDatabase -PiHoleServer $PiHoleServer -Password $Password ``` -Timestamp : 10/12/2026 6:30:00 PM -Total : 41 -Cached : 8 -Blocked : 9 -Forwarded : 24 +Timestamp : 10/19/2026 9:00:00 AM +Total : 1 +Cached : 1 +Blocked : 0 +Forwarded : 0 + +Timestamp : 10/19/2026 10:00:00 AM +Total : 1 +Cached : 1 +Blocked : 0 +Forwarded : 0 + +Timestamp : 10/19/2026 11:00:00 AM +Total : 1 +Cached : 1 +Blocked : 0 +Forwarded : 0 + +Timestamp : 10/19/2026 12:00:00 PM +Total : 1 +Cached : 1 +Blocked : 0 +Forwarded : 0 + +Timestamp : 10/19/2026 1:00:00 PM +Total : 1 +Cached : 1 +Blocked : 0 +Forwarded : 0 + +_(showing 5 of 9 results)_ ``` ### Get-PiHoleHistoryDatabaseClient @@ -1421,8 +1440,22 @@ Get-PiHoleHistoryDatabaseClient -PiHoleServer $PiHoleServer -Password $Password ``` -Timestamp : 10/12/2026 6:30:00 PM -Clients : {@{ClientId=3; Count=1}, @{ClientId=2; Count=1}, @{ClientId=5; Count=1}} +Timestamp : 10/19/2026 4:30:00 PM +Clients : @{ClientId=127.0.0.1; Count=2} + +Timestamp : 10/19/2026 4:00:00 PM +Clients : @{ClientId=127.0.0.1; Count=1} + +Timestamp : 10/19/2026 3:00:00 PM +Clients : @{ClientId=127.0.0.1; Count=1} + +Timestamp : 10/19/2026 2:00:00 PM +Clients : @{ClientId=127.0.0.1; Count=1} + +Timestamp : 10/19/2026 1:00:00 PM +Clients : @{ClientId=127.0.0.1; Count=1} + +_(showing 5 of 9 results)_ ``` ### Get-PiHoleNetworkGateway @@ -1518,7 +1551,7 @@ ProtoDown : False Address : 00:00:00:00:00:00 Broadcast : 00:00:00:00:00:00 Stats : @{RxBytes=; TxBytes=; Bits=64} -Addresses : {@{Family=inet; Scope=host; Flags=permanent; Prefixlen=8; Address=127.0.0.1; AddressType=loopback; Local=127.0.0.1; LocalType=loopback; Label=lo; Prefered=4294967295; Valid=4294967295; Cstamp=1791692112.02; Tstamp=1791692112.02}, @{Family=inet6; Scope=host; Flags=permanent; Prefixlen=128; Address=::1; AddressType=loopback; Prefered=4294967295; Valid=4294967295; Cstamp=1791692112.02; Tstamp=1791692112.02}} +Addresses : {@{Family=inet; Scope=host; Flags=permanent; Prefixlen=8; Address=127.0.0.1; AddressType=loopback; Local=127.0.0.1; LocalType=loopback; Label=lo; Prefered=4294967295; Valid=4294967295; Cstamp=1792275601.02; Tstamp=1792275601.02}, @{Family=inet6; Scope=host; Flags=permanent; Prefixlen=128; Address=::1; AddressType=loopback; Prefered=4294967295; Valid=4294967295; Cstamp=1792275601.02; Tstamp=1792275601.02}} Name : wlan0 Speed : @@ -1531,7 +1564,7 @@ Address : b8:27:eb:11:a4:d5 Broadcast : ff:ff:ff:ff:ff:ff PermAddress : b8:27:eb:11:a4:d5 Stats : @{RxBytes=; TxBytes=; Bits=64} -Addresses : {@{Family=inet; Scope=universe; Flags=; Prefixlen=24; Address=192.168.1.248; AddressType=private; Local=192.168.1.248; LocalType=private; Broadcast=192.168.1.255; BroadcastType=private; Label=wlan0; Prefered=70695; Valid=70695; Cstamp=1791692138.78; Tstamp=1791833220.34}, @{Family=inet6; Scope=link; Flags=permanent; Prefixlen=64; Address=fe80::ba27:ebff:fe11:a4d5; AddressType=link-local (LL); Prefered=4294967295; Valid=4294967295; Cstamp=1791692131.87; Tstamp=1791692131.87}} +Addresses : {@{Family=inet; Scope=universe; Flags=; Prefixlen=24; Address=192.168.1.248; AddressType=private; Local=192.168.1.248; LocalType=private; Broadcast=192.168.1.255; BroadcastType=private; Label=wlan0; Prefered=63207; Valid=63207; Cstamp=1792275626.13; Tstamp=1792422734.72}, @{Family=inet6; Scope=link; Flags=permanent; Prefixlen=64; Address=fe80::ba27:ebff:fe11:a4d5; AddressType=link-local (LL); Prefered=4294967295; Valid=4294967295; Cstamp=1792275620.88; Tstamp=1792275620.88}} ``` ### Get-PiHoleNetworkDevice @@ -1544,23 +1577,32 @@ Get-PiHoleNetworkDevice -PiHoleServer $PiHoleServer -Password $Password ``` -Id : 2 -HwAddr : ip-127.0.0.1 +Id : 1 +HwAddr : 00:00:00:00:00:00 Interface : lo -FirstSeen : 10/12/2026 6:31:26 PM -LastQuery : 10/12/2026 6:37:42 PM -NumQueries : 9 -MacVendor : -Ips : @{Ip=127.0.0.1; Name=localhost; LastSeen=10/12/2026 6:48:00 PM; NameUpdated=10/12/2026 6:48:00 PM} +FirstSeen : 10/18/2026 10:04:00 PM +LastQuery : 10/19/2026 4:32:55 PM +NumQueries : 40 +MacVendor : virtual interface +Ips : {@{Ip=127.0.0.1; Name=localhost; LastSeen=10/19/2026 4:38:00 PM; NameUpdated=10/19/2026 4:38:00 PM}, @{Ip=::1; Name=; LastSeen=10/19/2026 4:38:00 PM; NameUpdated=12/31/1969 6:00:00 PM}, @{Ip=0.0.0.0; Name=; LastSeen=10/19/2026 4:38:00 PM; NameUpdated=12/31/1969 6:00:00 PM}} -Id : 1 +Id : 3 HwAddr : 74:56:3c:bb:f4:0b Interface : wlan0 -FirstSeen : 10/12/2026 6:31:26 PM -LastQuery : 10/12/2026 6:31:26 PM -NumQueries : 34 +FirstSeen : 10/18/2026 10:46:44 PM +LastQuery : 10/18/2026 11:01:25 PM +NumQueries : 276 MacVendor : Giga-Byte Technology Co.,Ltd. -Ips : @{Ip=192.168.1.162; Name=; LastSeen=10/12/2026 6:48:00 PM; NameUpdated=12/31/1969 6:00:00 PM} +Ips : @{Ip=192.168.1.162; Name=; LastSeen=10/19/2026 4:38:00 PM; NameUpdated=12/31/1969 6:00:00 PM} + +Id : 2 +HwAddr : b8:27:eb:11:a4:d5 +Interface : wlan0 +FirstSeen : 10/18/2026 10:04:00 PM +LastQuery : 12/31/1969 6:00:00 PM +NumQueries : 0 +MacVendor : Raspberry Pi Foundation +Ips : {@{Ip=192.168.1.248; Name=; LastSeen=10/19/2026 4:38:00 PM; NameUpdated=12/31/1969 6:00:00 PM}, @{Ip=fe80::ba27:ebff:fe11:a4d5; Name=; LastSeen=10/19/2026 4:38:00 PM; NameUpdated=12/31/1969 6:00:00 PM}} ``` ### Remove-PiHoleNetworkDevice @@ -1613,8 +1655,8 @@ Get-PiHoleAuthStatus -PiHoleServer $PiHoleServer -Password $Password Valid : True Totp : False -Sid : zH7Z6NLKzAHxBNREdG6N5g= -Csrf : CgJVzV6Gp2nM1JY5ibWxpQ= +Sid : 1egtS0Zh/fgaBQSwCPexMw= +Csrf : 40b4sKeZDafsAQC+j7t1JA= Validity : 1800 Message : correct password ``` @@ -1634,68 +1676,40 @@ Algorithm : SHA1 Digits : 6 Period : 30 Offset : 0 -Secret : NQFB3X5S7SUPU3UZKSLNTHJEXLKJPZP4 -Codes : {282924, 721698, 735368, 749478…} +Secret : Q5K6L2DLLM65JSATZ7HU7LHC7W677747 +Codes : {619655, 185583, 505198, 995412…} ``` -### Get-PiHoleCurrentAuthSession +### Get-PiHoleAuthApp + +_This only generates a password. It was never activated on the test server, so it is safe to show here._ ```powershell -Get-PiHoleCurrentAuthSession -PiHoleServer $PiHoleServer -Password $Password +Get-PiHoleAuthApp -PiHoleServer $PiHoleServer -Password $Password ``` ``` -Id : 0 -CurrentSession : False -Valid : True -TlsLogin : True -TlsMixed : False -LoginAt : 10/12/2026 6:19:07 PM -LastActive : 10/12/2026 6:19:15 PM -ValidUntil : 10/12/2026 6:49:15 PM -RemoteAddress : 192.168.1.162 -UserAgent : Mozilla/5.0 (Windows NT 10.0; Microsoft Windows 10.0.26200; en-US) PowerShell/7.6.6 -XForwardedFor : -App : True -Cli : False +Password : 4ZafjS7tw7/RgKCph37MY2sM3IlznjNx0+74dQIU1Ns= +Hash : $BALLOON-SHA256$v=1$s=1024,t=32$BjLFnQsBZT7kZrcQJ6KIew==$v0oLwqzLRaScMhqFEUZJj4n3sBKbO2AeIXoHfYVeR+U= +``` -Id : 1 -CurrentSession : False -Valid : True -TlsLogin : True -TlsMixed : False -LoginAt : 10/12/2026 6:19:11 PM -LastActive : 10/12/2026 6:19:11 PM -ValidUntil : 10/12/2026 6:49:11 PM -RemoteAddress : 192.168.1.162 -UserAgent : Mozilla/5.0 (Windows NT 10.0; Microsoft Windows 10.0.26200; en-US) PowerShell/7.6.6 -XForwardedFor : -App : True -Cli : False +### Get-PiHoleCurrentAuthSession -Id : 2 -CurrentSession : False -Valid : True -TlsLogin : True -TlsMixed : False -LoginAt : 10/12/2026 6:31:46 PM -LastActive : 10/12/2026 6:31:46 PM -ValidUntil : 10/12/2026 7:01:46 PM -RemoteAddress : 192.168.1.162 -UserAgent : Mozilla/5.0 (Windows NT 10.0; Microsoft Windows 10.0.26200; en-US) PowerShell/7.6.6 -XForwardedFor : -App : True -Cli : False +```powershell +Get-PiHoleCurrentAuthSession -PiHoleServer $PiHoleServer -Password $Password +``` -Id : 3 +``` + +Id : 0 CurrentSession : True Valid : True TlsLogin : True TlsMixed : False -LoginAt : 10/12/2026 6:31:53 PM -LastActive : 10/12/2026 6:32:01 PM -ValidUntil : 10/12/2026 7:02:01 PM +LoginAt : 10/19/2026 4:29:51 PM +LastActive : 10/19/2026 4:29:55 PM +ValidUntil : 10/19/2026 4:59:55 PM RemoteAddress : 192.168.1.162 UserAgent : Mozilla/5.0 (Windows NT 10.0; Microsoft Windows 10.0.26200; en-US) PowerShell/7.6.6 XForwardedFor : @@ -1708,13 +1722,13 @@ Cli : False _Deletes a session by its ID (as shown by Get-PiHoleCurrentAuthSession), not the caller's own session._ ```powershell -Remove-PiHoleAuthSession -PiHoleServer $PiHoleServer -Password $Password -Id 2 +Remove-PiHoleAuthSession -PiHoleServer $PiHoleServer -Password $Password -Id 0 ``` ``` -Id : 2 +Id : 0 Status : Removed ``` diff --git a/tests/Authentication/Get-PiHoleAuthApp.Integration.Tests.ps1 b/tests/Authentication/Get-PiHoleAuthApp.Integration.Tests.ps1 new file mode 100644 index 0000000..fcba2ed --- /dev/null +++ b/tests/Authentication/Get-PiHoleAuthApp.Integration.Tests.ps1 @@ -0,0 +1,63 @@ +# Requires -Module Pester +# +# Integration tests that call a REAL Pi-hole server. Configure tests/IntegrationConfig.local.ps1 +# (copy it from IntegrationConfig.example.ps1) before running. Tests are skipped automatically +# if that file is missing. +# +# NOTE: these only generate app passwords - they never set the returned hash as +# webserver.api.app_pwhash, so the server's real app password and sessions are left untouched. + +# Config availability must be known at discovery time so the -Skip parameter on each It block +# (evaluated during discovery, before BeforeAll runs) sees the correct value. +$script:ConfigAvailable = Test-Path (Join-Path (Split-Path $PSScriptRoot -Parent) 'IntegrationConfig.local.ps1') + +Describe 'Get-PiHoleAuthApp (Integration)' -Tag 'Integration' { + BeforeAll { + Import-Module .\PiHoleShell\PiHoleShell.psm1 -Force + + # Recomputed here (not read from the discovery-time $script:ConfigAvailable above) because + # Pester runs discovery and run in separate scopes, so BeforeAll cannot see that value. + $configPath = Join-Path (Split-Path $PSScriptRoot -Parent) 'IntegrationConfig.local.ps1' + if (Test-Path $configPath) { + . $configPath + $script:PiHoleServer = $PiHoleServer + $script:PiHoleToken = $PiHoleToken + $script:PiHoleIgnoreSsl = $PiHoleIgnoreSsl + } + } + + It 'generates a new app password and its hash' -Skip:(-not $script:ConfigAvailable) { + $result = Get-PiHoleAuthApp -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl + + $result | Should -Not -BeNullOrEmpty + $result.Password | Should -Not -BeNullOrEmpty + $result.Hash | Should -BeLike '$BALLOON-SHA256$*' + } + + It 'generates a different password each time' -Skip:(-not $script:ConfigAvailable) { + $first = Get-PiHoleAuthApp -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl + $second = Get-PiHoleAuthApp -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl + + $second.Password | Should -Not -Be $first.Password + } + + It 'leaves the current app password working' -Skip:(-not $script:ConfigAvailable) { + Get-PiHoleAuthApp -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl | Out-Null + + $status = Get-PiHoleAuthStatus -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl + $status.Valid | Should -BeTrue + } + + It 'returns the raw API response when RawOutput is set' -Skip:(-not $script:ConfigAvailable) { + $result = Get-PiHoleAuthApp -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -RawOutput $true + + $result.app.password | Should -Not -BeNullOrEmpty + $result.app.hash | Should -Not -BeNullOrEmpty + } + + It 'errors when given a bad password' -Skip:(-not $script:ConfigAvailable) { + $result = Get-PiHoleAuthApp -PiHoleServer $script:PiHoleServer -Password 'definitely-not-the-real-token' -IgnoreSsl $script:PiHoleIgnoreSsl -ErrorVariable errOut -ErrorAction SilentlyContinue + + $errOut | Should -Not -BeNullOrEmpty + } +} diff --git a/tools/Update-ExampleOutput.ps1 b/tools/Update-ExampleOutput.ps1 index cbbff6e..2632e14 100644 --- a/tools/Update-ExampleOutput.ps1 +++ b/tools/Update-ExampleOutput.ps1 @@ -117,6 +117,11 @@ Add-Example -Category Authentication -FunctionName 'Get-PiHoleAuthTotp' ` -Invocation 'Get-PiHoleAuthTotp -PiHoleServer $PiHoleServer -Password $Password' ` -Result (Get-PiHoleAuthTotp -PiHoleServer $PiHoleServer -Password $PiHoleToken -IgnoreSsl $PiHoleIgnoreSsl) +Add-Example -Category Authentication -FunctionName 'Get-PiHoleAuthApp' ` + -Invocation 'Get-PiHoleAuthApp -PiHoleServer $PiHoleServer -Password $Password' ` + -Note 'This only generates a password. It was never activated on the test server, so it is safe to show here.' ` + -Result (Get-PiHoleAuthApp -PiHoleServer $PiHoleServer -Password $PiHoleToken -IgnoreSsl $PiHoleIgnoreSsl) + Add-Example -Category Authentication -FunctionName 'Get-PiHoleCurrentAuthSession' ` -Invocation 'Get-PiHoleCurrentAuthSession -PiHoleServer $PiHoleServer -Password $Password' ` -Result (Get-PiHoleCurrentAuthSession -PiHoleServer $PiHoleServer -Password $PiHoleToken -IgnoreSsl $PiHoleIgnoreSsl) From f1df2cf1e29c85805839d0fec6c7d2edd503ae25 Mon Sep 17 00:00:00 2001 From: Mike Madeja Date: Mon, 19 Oct 2026 17:00:56 -0500 Subject: [PATCH 7/7] fix: report "Gravity is already running" instead of a bare 409 FTL v6.8 answers POST /api/action/gravity with 409 while another run is in progress. Use ConvertTo-PiHoleFriendlyErrorMessage so the caller sees Pi-hole's own message, and add an integration test that starts a background run and checks a second call reports it. Co-Authored-By: Claude Opus 5.5 --- .../Actions/Update-PiHoleActionsGravity.ps1 | 4 +++- ...PiHoleActionsGravity.Integration.Tests.ps1 | 24 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/PiHoleShell/Public/Actions/Update-PiHoleActionsGravity.ps1 b/PiHoleShell/Public/Actions/Update-PiHoleActionsGravity.ps1 index 3e23c04..8791b6e 100644 --- a/PiHoleShell/Public/Actions/Update-PiHoleActionsGravity.ps1 +++ b/PiHoleShell/Public/Actions/Update-PiHoleActionsGravity.ps1 @@ -61,7 +61,9 @@ Update-PiHoleActionsGravity -PiHoleServer "http://pihole.domain.com:8080" -Passw } catch { - Write-Error -Message $_.Exception.Message + # Surfaces Pi-hole's own message, e.g. "Gravity is already running" for the 409 FTL v6.8+ + # returns while another run is in progress, instead of a bare "409 (Conflict)" + Write-Error -Message (ConvertTo-PiHoleFriendlyErrorMessage -ErrorRecord $_) } finally { diff --git a/tests/Actions/Update-PiHoleActionsGravity.Integration.Tests.ps1 b/tests/Actions/Update-PiHoleActionsGravity.Integration.Tests.ps1 index da81455..c7d440b 100644 --- a/tests/Actions/Update-PiHoleActionsGravity.Integration.Tests.ps1 +++ b/tests/Actions/Update-PiHoleActionsGravity.Integration.Tests.ps1 @@ -41,6 +41,30 @@ Describe 'Update-PiHoleActionsGravity (Integration)' -Tag 'Integration' { $result | Should -Not -BeNullOrEmpty } + It 'reports a clear error when a gravity update is already running' -Skip:(-not $script:ConfigAvailable) { + # FTL v6.8+ refuses a second concurrent run with 409. Start one in the background, give it + # a moment to get going, then try another. + $moduleRoot = (Resolve-Path .\PiHoleShell\PiHoleShell.psm1).Path + $job = Start-ThreadJob -ArgumentList $moduleRoot, $script:PiHoleServer, $script:PiHoleToken, $script:PiHoleIgnoreSsl -ScriptBlock { + param($ModulePath, $Server, $Token, $IgnoreSsl) + Import-Module $ModulePath -Force + Update-PiHoleActionsGravity -PiHoleServer $Server -Password $Token -IgnoreSsl $IgnoreSsl -Confirm:$false + } + try { + Start-Sleep -Seconds 2 + $result = Update-PiHoleActionsGravity -PiHoleServer $script:PiHoleServer -Password $script:PiHoleToken -IgnoreSsl $script:PiHoleIgnoreSsl -Confirm:$false -ErrorVariable errOut -ErrorAction SilentlyContinue + Write-Host "Error: [$($errOut[-1])]" + + $result | Should -BeNullOrEmpty + "$($errOut[-1])" | Should -Be 'Gravity is already running' + } + finally { + # Let the background run finish so it doesn't collide with later tests + $job | Wait-Job -Timeout 600 | Receive-Job -ErrorAction SilentlyContinue | Out-Null + $job | Remove-Job -Force + } + } + It 'errors when given a bad password' -Skip:(-not $script:ConfigAvailable) { $result = Update-PiHoleActionsGravity -PiHoleServer $script:PiHoleServer -Password 'definitely-not-the-real-token' -IgnoreSsl $script:PiHoleIgnoreSsl -Confirm:$false -ErrorVariable errOut -ErrorAction SilentlyContinue Write-Host "Error ($($errOut.Count) entries, showing last): [$($errOut[-1])]"