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

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

 

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.

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

[quote quote=253232]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.
[/quote] 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

$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?