Pihole.bat - Simple Windows Batch file wrapper for Pi-Hole API


I've created a Batch file to use the Pi-Hole API and am sharing it here, in case anyone else has use for it.

Get it from GitHub: https://raw.githubusercontent.com/silv3rr/pihole/master/pihole.bat
( repos: https://github.com/silv3rr/pihole )

Using it you can enable and disable Pi-Hole from Windows and use all other API parameters, like the in the web interface. For example this will disable Pi-hole for 1 minute (use Start > Run or better Command Prompt):

C:\pihole.bat disable 60

status: disabled

or, get some data:

C:\pihole.bat overTimeData10mins

ads_over_time 2018-05-24T10:55:00Z: 35
ads_over_time 2018-05-24T11:05:00Z: 47
ads_over_time 2018-05-24T11:15:00Z: 75
domains_over_time 2018-05-24T10:55:00Z: 35
domains_over_time 2018-05-24T11:05:00Z: 47
domains_over_time 2018-05-24T11:15:00Z: 75

It needs "curl" and optionally "jq" (available from chocolatey.org). But if it cannot find curl it will also look for wget and powershell and use those instead. If jq (or powershell) is found it will be used to format the JSON output, if not you get normal unformatted JSON.

You will need to set your API Token inside the .bat using the "auth" variable. Some parameters work without it, but enable/disable do need it.

For help: pihole.bat -h

1 Like

That’s some heavy duty batch file coding :slight_smile:

1 Like

Thanks for this. I find it handier to have a desktop shortcut to enable and disable blocking to visit locked domains such as visits via goole shopping ads or to comply with sites refusing to show content I want to see because of the ad blocking.

I haven't bothered to password protect my Pihole interface and found that means I need no API token.

1 Like