0

I want to use the following powershell code to iterate through a collection of IP addresses and check whether they have a DNS entry in InfoBlox.

Set-IBConfig -ProfileName 'MyGrid' -WAPIHost dns.xx.xxx -WAPIVersion latest - 
Credential (Get-Credential) -SkipCertificateCheck
$resultsFolder = "C:\Users\x\Documents\20220920"
$AviClusterList = 'C:\Users\x\Documents\20220920\AviCluster.csv'
$AviClusters = Import-csv $AviClusterList
foreach ($AviCluster in $AviClusters) {
    $AviClusterName = $AviCluster.FQDN
    $SEVirtualIPs = Import-Csv "$resultsFolder\$AviClusterName.csv"
    foreach($SEVirtualIP in $SEVirtualIPs){
         try {
         $ipObj = Get-IBObject -type ipv4address -filters 
   'status=USED',"ip_address=$($SEVirtualIP.'Service Engine Virtual IPs')"
    }
    catch {
    "A network was not found for this address"
    }
    $ipObj `
    | select ip_address `
    | Select-Object *,@{n="Infoblox Reservation Name";e={$ipObj.names}} `
    | Select-Object *,@{n="Status";e={$ipObj.status}} `
    | Select-Object *,@{n="In Conflict";e={$ipObj.is_conflict}} `
    | Export-csv -Path "$resultsFolder\AviVirtualIPReservations.csv" -append -NoTypeInformation -Force
    }
}

Currently I have Catch statement above. I would like to get that catch statement added to the export CSV against the IP. That way I know what IP reservation doesn't have a network.

Mike Pennington
  • 41,899
  • 19
  • 136
  • 174
  • Change `"A network was not found for this address"` to `$ipObj = @{ status = "A network was not found for this address" }` – Mathias R. Jessen Sep 22 '22 at 13:42
  • Thank you @MathiasR.Jessen that worked nearly as I had hoped. On the output CSV it inserts the comment as a separate row, I was hoping to append it to the end of the row. Do you think that is possible? – asthmatic_weasel Sep 22 '22 at 14:08
  • What do you mean by "append it to the row"? Tagging it on the end after the last field would make your CSV not-a-CSV-anymore and you might run into issues with other CSV-parsing tools simply dropping the data completely on import – Mathias R. Jessen Sep 22 '22 at 14:11
  • when I mean append to the end of the row, I should of been clearer and mean in a new column. So Column A is currently selected IP address, Column B is Reservation Name, Column C is Status, Column D is in Conflict, I would like the error message in Column E. – asthmatic_weasel Sep 22 '22 at 14:38
  • By the way you can continue a line with a `|` or a `,`. – js2010 Sep 22 '22 at 16:31

0 Answers0