Advertisement
upz

Get-DhcpFilterInformation

upz
Dec 3rd, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function Get-DhcpFilterInformation
  2. {
  3.     [CmdLetBinding()]
  4.     Param()
  5.     DynamicParam
  6.     {        
  7.         $ParameterName = 'Scope'
  8.        
  9.         $RuntimeParameterDictionary = New-Object System.Management.Automation.RuntimeDefinedParameterDictionary
  10.  
  11.         $AttributeCollection = New-Object System.Collections.ObjectModel.Collection[System.Attribute]
  12.        
  13.         $ParameterAttribute = New-Object System.Management.Automation.ParameterAttribute
  14.         $ParameterAttribute.Mandatory = $true
  15.         $ParameterAttribute.Position = 1
  16.  
  17.         $AttributeCollection.Add($ParameterAttribute)
  18.  
  19.         $arrSet = (Get-DhcpServerv4Scope).ScopeId
  20.         $ValidateSetAttribute = New-Object System.Management.Automation.ValidateSetAttribute($arrSet)
  21.  
  22.         $AttributeCollection.Add($ValidateSetAttribute)
  23.         $RuntimeParameter = New-Object System.Management.Automation.RuntimeDefinedParameter($ParameterName, [string], $AttributeCollection)
  24.         $RuntimeParameterDictionary.Add($ParameterName, $RuntimeParameter)
  25.         return $RuntimeParameterDictionary
  26.     }
  27.  
  28.     begin
  29.     {
  30.         $Scope = $PsBoundParameters[$ParameterName]
  31.     }
  32.    
  33.     process
  34.     {
  35.         $clientinfo = @()
  36.         $leases = Get-DhcpServerv4Lease -ScopeId $Scope
  37.         foreach ($item in (Get-DhcpServerv4Filter))
  38.         {
  39.             foreach($lease in $leases)
  40.             {
  41.                 if ($lease.ClientId -eq $item.MacAddress)
  42.                 {
  43.                     $obj = New-Object -TypeName psobject
  44.                     try
  45.                     {
  46.                         $name = Resolve-DnsName $lease.IPAddress.tostring() -QuickTimeout -ErrorAction Stop
  47.                         $obj | Add-Member -MemberType NoteProperty -Name PcName -Value $name.NameHost
  48.                     }
  49.                     catch
  50.                     {
  51.                         $name = "N/A"
  52.                         $obj | Add-Member -MemberType NoteProperty -Name PcName -Value $name
  53.                     }
  54.        
  55.                     $obj | Add-Member -MemberType NoteProperty -Name IP -Value $lease.IPAddress
  56.                     $obj | Add-Member -MemberType NoteProperty -Name MAC -Value $lease.ClientId
  57.                     $obj | Add-Member -MemberType NoteProperty -Name ListType -Value $item.List
  58.                     $obj | Add-Member -MemberType NoteProperty -Name Description -Value $item.Description
  59.        
  60.                     $clientinfo += $obj
  61.                 }
  62.             }
  63.         }
  64.        
  65.         $clientinfo
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement