Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Get-DhcpServerv4Lease -allleases -ScopeId #myscopeIDhere | Select-Object @{expression= {$_.hostname}; label='name' } | export-CSV -notypeinformation C:dhcpLeaseLog.csv
- import-module activedirectory
- #get input CSV
- $leaselogpath = "c:DHCPLeaseLog.csv"
- Import-csv -path $leaselogpath |
- #query AD for computer name based on csv log
- foreach-object `
- {
- $NameResult = Get-ADComputer -Filter *
- If ($NameResult -eq $null) {$RogueSystem = $_.name}
- $RogueSystem | Out-File C:DHCPRogueClients.txt -Append
- $RogueSystem = $null
- }
- Get-Content C:DHCPRogueClients.txt | Select-Object -Unique | Out-File C:DHCPRogueClientsFinal.txt
- Remove-Item C:DHCPRogueClients.txt
- #send email to sysadmin
- $smtpserver = #my email server IP address here
- $from="abcd@abcdefg.com"
- $to="sysadmin@abcdefg.com"
- $subject="Non-AD joined DHCP clients"
- $body= (Get-Content C:DHCPRogueClientsFinal.txt) -join '<BR> <BR>'
- $mailer = new-object Net.Mail.SMTPclient($smtpserver)
- $msg = new-object Net.Mail.MailMessage($from,$to,$subject,$body)
- $msg.IsBodyHTML = $true
- $mailer.send($msg)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement