I am trying to get a JSON array of MAC addresses and associated IP addresses of DHCP leases from a Windows DHCP server using PowerShell.
Using this:
Get-DhcpServerv4Lease -ScopeId 192.168.0.0 | Where-Object {$_.AddressState -eq "ActiveReservation"} | Select-Object -Property ClientId,IPAddress | ConvertTo-Json
I get this output:
[
{
"ClientId": "00-11-22-33-44-55",
"IPAddress": {
"Address": 12345678,
"AddressFamily": 2,
"ScopeId" : null,
"IPAddressToString": "192.168.0.2"
}
},
{
"ClientId": "00-11-22-33-44-66",
"IPAddress": {
"Address": 12345679,
"AddressFamily": 2,
"ScopeId" : null,
"IPAddressToString": "192.168.0.3"
}
}
]
But I only want the ClientId and value of IPAddressToString, not the other properties:
[
{
"ClientId": "00-11-22-33-44-55",
"IPAddressToString": "192.168.0.2"
},
{
"ClientId": "00-11-22-33-44-66",
"IPAddressToString": "192.168.0.3"
}
]
Is this possible in a one-liner?