SCENARIO
To simplify this down to it's easiest example:
I have a Windows 2008 R2 standard DC with the DHCP server role. It hands out IPs via various IPv4 scopes, no problem there.
WHAT I'D LIKE
I would like a way to create a notification/eventlog entry/similar whenever a device gets a DHCP address lease and that device IS NOT a domain joined computer in Active Directory. It doesn't matter to me whether it is custom Powershell, etc.
Bottom line = I'd like a way to know when non-domain devices are on the network without using 802.1X at the moment. I know this won't account for static IP devices. I do have monitoring software that will scan the network and find devices, but it isn't quite this granular in detail.
RESEARCH DONE/OPTIONS CONSIDERED
I don't see any such possibilities with the built in logging.
Yes, I'm aware of 802.1X and have the ability to implement it long-term at this location but we are some time away from a project like that, and while that would solve network authentication issues, this is still helpful to me outside of 802.1X goals.
I've looked around for some script bits, etc. that might prove useful but the things I'm finding lead me to believe that my google-fu is failing me at the moment.
I believe the below logic is sound (assuming there isn't some existing solution):
- Device receives DHCP address
- Event log entry is recorded (event ID 10 in the DHCP audit log should work (since a new lease is what I'd be most interested in, not renewals): http://technet.microsoft.com/en-us/library/dd759178.aspx)
- At this point a script of some kind would probably have to take over for the remaining "STEPS" below.
- Somehow query this DHCP log for these event ID 10's (I would love push, but I'm guessing pull is the only recourse here)
- Parse the query for the name of the device being assigned the new lease
- Query AD for the device's name
- IF not found in AD, send a notification email
If anyone has any ideas on how to properly do this, I'd really appreciate it. I'm not looking for a "gimme the codez" but would love to know if there are alternatives to the above list or if I'm not thinking clear and another method exists for gathering this information. If you have code snippets/PS commands you'd like to share to help accomplish this, all the better.
With much thanks to ErikE and the others here, I've gone down a path...I won't say it's the right path, but the Powershell script I've come up with does the trick.
The code is below if anyone wants it. Just run it manually pointing at each DHCP server or schedule it (again pointing to each DHCP server in the script).
What the script does:
What you'll need:
The script uses the AD module (
import-module activedirectory
) so it is best run on an AD DC running DHCP. If this isn't the case for you, you can install the AD powershell module: http://blogs.msdn.com/b/rkramesh/archive/2012/01/17/how-to-add-active-directory-module-in-powershell-in-windows-7.aspxYou'll also need Quest's AD Powershell cmdlets found here: http://www.quest.com/powershell/activeroles-server.aspx . Install THESE BEFORE running the script or it will fail.
The script itself (sanitized, you'll need to setup some of the variables to suit your needs like the input file names, domain to connect to, dhcp server to connect to, email settings near the end, etc.):
Hope that helps someone else!
OK, I´m not sure I´m following etiquette here but am posting a second answer instead of editing my previous one, as it did contain some info which may be of use to somebody even if proven irrelevant to this case. If that makes me an idiot in this forum feel free to inform me of my erroneous ways.
The problem is divided into several parts, here are suggestions for the ones I find most interesting. Without examples from the log this is the best I can do, so it's just suggestions not solutions.
To parse the log use
get-content
with the-wait
parameter. For my use case it's enough to find an error in an error log.This is what worked for my own use case, forgive the formatting:
Instead of the
$_ -match "ERROR"
you would need to separate the log ID field and the computer name somehow. I'm not sure how to go about that in the best way right now, but sincewhere-object -match
gives regex support I guess that could be an option. You could also begin by storing the $_ variable in another new variable, to be able to pick it up at your convenience later in the pipeline, inside nested foreach loops etc.Assuming you can get at the computername, I guess the
get-adcomputer
cmdlet would be your simplest way of querying your AD (import-module activedirectory
), and I guess on error send mail?Using the
import-csv
would of course be far more elegant in your case, but I'm not aware of any way of tailing it (if anybody happens to read this and knows a trick up that alley then please, please share).Under the assumption that you are certain of the Event ID, and that no other events log to this ID in the DHCP log but the ones you are interested in, push is indeed an option.
1) Open the Server Manager, go to the DHCP log in Event Viewer.
2) Find a representative entry which you wish to attach your action to. Select it and right click.
3) Choose "Attach Task To This Event".
4) The Task Creation Wizard opens, take it away from there...
There is actually an explicit email option, but if you need more logic than that you are of course free to use the start-a-program option to fire up powershell.exe and attach a script to it. There are plenty of excellent googleable howtos on how to let the Task Manager run powershell scripts if you need guidance.
The straight away alternative I see is to use pull by parsing the Event Log using powershell at scheduled intervals. "The Microsoft Scripting Guy", aka Ed Wilson has written some awesome blog posts on how to parse the Event Log using the cmdlets available in the different versions of powershell, so taking his blog as a starting point would be my suggestion.
As for actual cmdlets I don´t have the time right now to pull out my stash of handy snippets, but will look in again in a day or two and may contribute if nobody else has pitched in with some well chosen ones, or you haven´t solved it all by yourself :-)
While this doesn't address your desired solution, an option that may achieve your goal is to utilize
arpwatch
(link) to notify you when a new (previously unseen) host is seen on the network.A Windows alternative to
arpwatch
appears to be decaffeinatid but I've never used it so can't speak for it good or bad.