Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Get-DhcpFilterInformation
- {
- #[CmdLetBinding()]
- Param
- (
- [Parameter(Mandatory=$true)]
- [string]$ip,
- [Parameter(Mandatory=$true)]
- [validateset("Allow","Deny","Both")]
- [string]$type = "Both"
- )
- DynamicParam
- {
- $ParameterName = 'Scope'
- $RuntimeParameterDictionary = New-Object System.Management.Automation.RuntimeDefinedParameterDictionary
- $AttributeCollection = New-Object System.Collections.ObjectModel.Collection[System.Attribute]
- $ParameterAttribute = New-Object System.Management.Automation.ParameterAttribute
- $ParameterAttribute.Mandatory = $true
- $ParameterAttribute.Position = 1
- $AttributeCollection.Add($ParameterAttribute)
- $arrSet = (Get-DhcpServerv4Scope).ScopeId
- $ValidateSetAttribute = New-Object System.Management.Automation.ValidateSetAttribute($arrSet)
- $AttributeCollection.Add($ValidateSetAttribute)
- $RuntimeParameter = New-Object System.Management.Automation.RuntimeDefinedParameter($ParameterName, [string], $AttributeCollection)
- $RuntimeParameterDictionary.Add($ParameterName, $RuntimeParameter)
- return $RuntimeParameterDictionary
- }
- begin
- {
- $Scope = $PsBoundParameters[$ParameterName]
- }
- process
- {
- $clientinfo = @()
- if ($type -eq 'Both')
- {
- $filter = Get-DhcpServerv4Filter | where {$_.List -like "*"}
- }
- else
- {
- $filter = Get-DhcpServerv4Filter | where {$_.List -eq $type}
- }
- $lease = Get-DhcpServerv4Lease -ScopeId $Scope | where {$_.IPAddress -eq $ip}
- foreach ($item in $filter)
- {
- if ($lease.ClientId -eq $item.MacAddress)
- {
- $obj = New-Object -TypeName psobject
- try
- {
- $name = Resolve-DnsName $lease.IPAddress.tostring() -QuickTimeout -ErrorAction Stop
- $obj | Add-Member -MemberType NoteProperty -Name PcName -Value $name.NameHost
- }
- catch
- {
- $name = "N/A"
- $obj | Add-Member -MemberType NoteProperty -Name PcName -Value $name
- }
- $obj | Add-Member -MemberType NoteProperty -Name IP -Value $lease.IPAddress
- $obj | Add-Member -MemberType NoteProperty -Name MAC -Value $lease.ClientId
- $obj | Add-Member -MemberType NoteProperty -Name ListType -Value $item.List
- $obj | Add-Member -MemberType NoteProperty -Name Description -Value $item.Description
- $clientinfo += $obj
- }
- if ($clientinfo -ne $null)
- {
- break
- }
- }
- if ($clientinfo -ne $null)
- {
- $clientinfo
- }
- else
- {
- Write-Host -ForegroundColor Red "No Client with $ip in $type List"
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement