Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Get-DhcpFilterInformation
- {
- [CmdLetBinding()]
- Param()
- 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 = @()
- $leases = Get-DhcpServerv4Lease -ScopeId $Scope
- foreach ($item in (Get-DhcpServerv4Filter))
- {
- foreach($lease in $leases)
- {
- 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
- }
- }
- }
- $clientinfo
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement