-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
56 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<# | ||
.Synopsis | ||
Search DHCP for the specified MAC address | ||
.DESCRIPTION | ||
This function enumerates through each scope in either a defined site or the current site and displays any DHCP lease or reservation that matches the MAC address specified | ||
.EXAMPLE | ||
Get-Mac -Mac 000000000000 | ||
.EXAMPLE | ||
Get-Mac -Mac 0000 -DhcpSite CONTOSO | ||
.EXAMPLE | ||
Get-Mac -Mac 000000 -DhcpSite * | ||
#> | ||
|
||
function Get-Mac | ||
{ | ||
Param | ||
( | ||
[Parameter(Mandatory=$true, | ||
ValueFromPipelineByPropertyName=$true, | ||
Position=0)] | ||
$Mac, | ||
|
||
[Parameter(Mandatory=$false, | ||
ValueFromPipelineByPropertyName=$false, | ||
Position=1)] | ||
$DhcpSite | ||
) | ||
|
||
Begin | ||
{ | ||
$MacAddress = $Mac -replace '..(?!$)', '$&-' | ||
$Leases = @() | ||
$DhcpServers = Get-DhcpServerInDC | Where-Object {$_.DnsName -like "$DhcpSite*"} | ||
} | ||
Process | ||
{ | ||
$i = 1 | ||
foreach ($DhcpServer in $DhcpServers.DnsName) | ||
{ | ||
Write-Progress -Id 1 -Activity "Gathering DHCP Scopes" -Status "from $DhcpServer" -PercentComplete ($i++ / $DhcpServers.Count * 100) | ||
$DhcpScopes = Get-DhcpServerv4Scope -ComputerName $DhcpServer | ||
|
||
$j = 1 | ||
foreach ($DhcpScope in $DhcpScopes.ScopeId) | ||
{ | ||
Write-Progress -ParentId 1 -Activity "Gathering DHCP Leases" -Status "from $DhcpScope" -PercentComplete ($j++ / $DhcpScopes.Count * 100) | ||
$Leases += Get-DhcpServerv4Lease -ComputerName $DhcpServer -ScopeId $DhcpScope | ||
} | ||
} | ||
} | ||
End | ||
{ | ||
Write-Host "Found MAC Address $MacAddress in the following locations:" | ||
$Leases | Where-Object {$_.ClientId -Match "$MacAddress"} | ||
} | ||
} |