DHCP Approval using Azure Automation and Powershell

I wanted to try to prevent someone from bringing in an unapproved device onto our local network by simply plugging it into an Ethernet jack and pulling an IP address using DHCP. Microsoft's DHCP server service has a feature named DHCP Filters included with the Windows Server DHCP Server service which allows for MAC address white/black listing. I was able to use a combination of various Microsoft and Azure features to automate the process of approving and adding MAC addresses to our whitelist. Below is an explanation of how I was able to achieve this.

Resources needed:
Azure Automation Hybrid Worker agent installed on DHCP server
Azure Automation Runbook with a webhook to start it
Microsoft Power Automation Flow (formerly Microsoft Flow)
Powershell
Windows Task Scheduler
Microsoft Office 365 Outlook and SharePoint

The first step is to configure your Windows Server DHCP service scope so that IP addresses are only provided to computers with MAC addresses in the Allow List. The Deny list is optional:



Next, add a scheduled task on the DHCP server to run every minute which monitors for events indicating that a computer tried to obtain an IP address from the DHCP server but was denied due to not having its MAC address in the Allow list.

The scheduled task should run the Powershell script below every minute. It will pull the latest relevant event from Event Viewer, write the output to an XML file, and email the file to a mailbox for further processing.



The script above generates an XML file containing the computer name and MAC address, writes it to a file then emails it to an email address that can be monitored by a Microsoft Power Automation Flow job. Here's a visual image of the Flow:

Flow Connections needed:
Approvals
Office 365 Outlook
SharePoint


Details of each step in the Flow:






The approval process triggers an email with a link to either deny or approve the request for the computer to obtain an IP address. If you have the Microsoft Power Automation app on your phone you'll also get a push notification to which you can respond deny or approve. The name of the computer is displayed in the email notification and the push notification.

If you approve the request a webhook is fired. The webhook needs to be a link to an Azure Automation runbook which runs on a Hybrid Worker agent installed on the DHCP server. The code for the Runbook is below:

Comments

Popular posts from this blog

Auto-installing extensions on Firefox using Intune

Disable DNS over HTTPS in Firefox using Intune

Moving Applocker control from Group Policy to Intune