1

I use this command line to search free IP Address from IPAM,

Get-IpamRange -StartIPAddress 143.219.186.1 -EndIPAddress 143.219.187.254 | Find-IpamFreeAddress

This command only give available IP that are not listed on IPAM IP Inventory. I have a column called "IP Address Status" that had value of Free, Assigned, Reserved, or Submitted. I only want to find free IP Address listed from IPAM based on "Free".

Does anyone know what command that can search only "Free" address?

4

2 回答 2

1

Shot in the dark but what about this:

Get-IpamRange -StartIPAddress 143.219.186.1 -EndIPAddress 143.219.187.254 | Find-IpamFreeAddress | Where-Object {$_."IP Address Status" -eq "Free"}

于 2013-11-13T14:14:22.480 回答
0

I found a long coded answer for specific column "Free" with groups,

clear-host

Function Get-FreeAddress
{  #Example call:
     #Get-FreeAddress -Env:"Prod" -Container:"H07" -NumIPs:3 -GiveInfo:$false
    PARAM(
         [Parameter(Mandatory=$true,ValueFromPipeline=$true,HelpMessage="Environment info (Prod or NonProd)")]
         [ValidateNotNullOrEmpty()]
            [System.String]$Env,
         [Parameter(Mandatory=$false,HelpMessage="Container Info (ie. H01, H02, etc,,")]
         [ValidateNotNullOrEmpty()]
            [System.String]$Container,
         [Parameter(Mandatory=$false,HelpMessage="IP Count to return")]
         [ValidateNotNullOrEmpty()]
            [Int]$NumIPs,
         [switch]$GiveInfo = $False
    )
  Begin {
    If ($NumIPs -eq "" -or $NumIPs -eq $null) {$NumIPs = 1}
        #Nothing Necessary to process
    } #Begin

  Process {            

            $cnt = 1
            $IPOut = @()
            $Check = "Env=$($Env);*$($Container)*"
            $Ranges = Get-IpamRange -AddressFamily IPv4 | Where{$_.customconfiguration -like $check} | Sort Customconfiguration

            :RangeLoop Foreach ($Rng in $Ranges)
            {
                if($GiveInfo){Write-Host "Range: "$Rng.networkid}
                $ipaddinfo = Get-Ipamsubnet -networkid $Rng.networkid | get-ipamaddress | Where{$_.IPAddressState -eq 'Free'}
                :IPLoop foreach ($ipinfo in $ipaddinfo)
                {
                    If ($cnt -le $NumIPs)
                    {
                        if($GiveInfo){Write-Host "`t$($cnt):" $ipinfo.Address " : " $ipinfo.IPAddressState}
                        $cnt = $cnt + 1
                        $IPOut += $ipinfo.Address
                    }
                    Else
                    {Break RangeLoop}
                }
            }
            Return $IPOut
          }
}

Get-FreeAddress -Env:"Prod" -Container:"H07" -NumIPs:2 -GiveInfo:$false
于 2013-11-14T14:11:11.090 回答