Last active
July 18, 2016 07:44
-
-
Save Madawar/52cd046894d89c8a4a6e40dfe4025047 to your computer and use it in GitHub Desktop.
Clean out Mobile devices from your DHCP by using a powershell script.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Put your server Scope | |
$scope = "192.168.1.0" | |
#Put your DHCP Server Name | |
$dhcpserver = "dhcpserver.contoso.com" | |
#Fileshare unc path. Your Shared CSV file should have atleast one column Mac with the Mac-Address in the format E0-19-27-42-92-AC | |
$AllowedList = "\\shareserver\ITSoftware\MacAddress.csv" | |
#Get Active Leases | |
$leases = Get-DhcpServerv4Lease -ComputerName $dhcpserver -ScopeId $scope | Where-Object {$_.HostName -like 'android-*' -or $_.HostName -like 'Windows-*' -or $_.HostName -like '*Nokia*' -or $_.HostName -like '*Phone*'} | |
#Get Allowed CSV put this file in a shared folder and put in CSV file name here | |
if((Get-Content $AllowedList) -eq $Null){ | |
Write-Host "No Whitelist Found Stopping as this will delete all Mobile Leases" | |
exit | |
} | |
$csv = Import-Csv $AllowedList | |
ForEach ($lease in $leases ){ | |
#Check if lease is whitelisted in Shared CSV file | |
$found = $csv | where {$_.Mac -eq $lease.ClientId.ToUpper()} | |
if($found){ | |
Write-Host "Skipping Allowed User" | |
}else{ | |
#Remove-DhcpServerv4Lease -ComputerName $dhcpserver -ScopeId $scope -ClientId $lease.ClientId | |
#Add-DhcpServerv4Filter -List Deny -MacAddress $lease.ClientId -ComputerName $dhcpserver | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment