IPAM powershell to find and reserve an ip – Find-IpamFreeAddress

Welcome Forums General PowerShell Q&A IPAM powershell to find and reserve an ip – Find-IpamFreeAddress

Viewing 4 reply threads
  • Author
    Posts
    • #253205
      Participant
      Topics: 2
      Replies: 4
      Points: 29
      Rank: Member

      Hi

       

      I am having issues getting the right info from ipam windows with powershell

       

      here is what i type to get an ip

      Get-IpamRange -StartIPAddress “10.102.4.25” -EndIPAddress “10.102.5.254” | Find-IpamFreeAddress -NumAddress 1 -TestReachability

       

      it gets me result but i only want an ip that is not ready

       

      I tried | Where-Object … but i dont know what parameter to call

      Nothing is documented well or seems i dont get it

      I want the next ip that is not ready and to be able to store in a variable

       

      Thanks for the help

       

      Mike

       

    • #253232
      Participant
      Topics: 8
      Replies: 568
      Points: 2,170
      Helping Hand
      Rank: Community Hero

      What exactly did you search for? First search result..

      https://docs.microsoft.com/en-us/powershell/module/ipamserver/find-ipamfreeaddress?view=win10-ps

      The Find-IpamFreeAddress cmdlet gets one or more free IP addresses from a range of IP addresses in IP Address Management (IPAM). If you specify the NumAddress parameter, the cmdlet returns the requested number of free IPv4 addresses. If you do not specify the NumAddress parameter, the cmdlet returns a single free IP address.

    • #253238
      Participant
      Topics: 2
      Replies: 4
      Points: 29
      Rank: Member

      Here is the line I am using…

       

      Get-IpamRange -StartIPAddress “10.102.4.25” -EndIPAddress “10.102.5.254” | Find-IpamFreeAddress -NumAddress 1 -TestReachability

       

      but i need to identify and use if reachability is false

      • This reply was modified 3 weeks, 4 days ago by mbmondor75.
    • #253523
      Participant
      Topics: 2
      Replies: 4
      Points: 29
      Rank: Member

      What exactly did you search for? First search result..

      https://docs.microsoft.com/en-us/powershell/module/ipamserver/find-ipamfreeaddress?view=win10-ps

      The Find-IpamFreeAddress cmdlet gets one or more free IP addresses from a range of IP addresses in IP Address Management (IPAM). If you specify the NumAddress parameter, the cmdlet returns the requested number of free IPv4 addresses. If you do not specify the NumAddress parameter, the cmdlet returns a single free IP address.

      I actually need to be able to find the ip, check the status and after reserve it. if the ip can ping i dont want to use it

    • #254270
      Participant
      Topics: 2
      Replies: 4
      Points: 29
      Rank: Member

      $FreeIP=Get-IpamRange -StartIPAddress “10.102.4.25” -EndIPAddress “10.102.5.254” | Find-IpamFreeAddress -NumAddress 5 -TestReachability
      If($FreeIP){
      ForEach($IP in $FreeIP){
      If($IP.PingStatus -eq ‘NoReply’){
      Write-Host “Free IP found: $($IP.IpAddress)”
      Set-IpamAddress -IpAddress ($IP.IpAddress).IPAddressToString
      #-ManagedByService IPAM -ServiceInstance localhost -DeviceType Host -IpAddressState In-Use -AssignmentType Static -DeviceName $hostname -ForwardLookupZone croixbleue.corp -ForwardLookupPrimaryServer v1adds01 -ReverseLookupZone 4.102.10.in-addr.arpa -ReverseLookupPrimaryServer v1adds01 -PassThru | select @{N=”Name”;E={$_.DeviceName}}, @{N=”IpV4Address”;E={$_.IPaddress}} | Add-DnsServerResourceRecord -A -ZoneName “croixbleue.corp” -ComputerName $hostname -CreatePtr
      }
      }
      }

       

      Set-IpamAddress : No MSFT_IPAM_Address objects found with property ‘Address’ equal to ‘10.102.4.131’. Verify the value of the property and retry.
      At line:6 char:13
      + Set-IpamAddress -IpAddress ($IP.IpAddress).IPAddressToString
      + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo : ObjectNotFound: (10.102.4.131:IPAddress) [Set-IpamAddress], CimJobException
      + FullyQualifiedErrorId : CmdletizationQuery_NotFound_Address,Set-IpamAddress

       

      What is wrong with my lines?

Viewing 4 reply threads
  • You must be logged in to reply to this topic.