Need help with nested if else

Maheswar Reddy 1 Reputation point
2021-02-27T14:22:17.957+00:00

Hi all, Am trying to compare list of IPs against an excel (one excel with 3 sheets). it should fetch respective computer name; if not found, just say "not found". My script is executing 3 result for each search. please suggest.![72587-technet.png][1] [1]: /api/attachments/72587-technet.png?platform=QnA

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,602 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Rich Matheisen 47,501 Reputation points
    2021-02-27T15:32:00.58+00:00

    Please don't post pictures of your code. Use the "Code Sample" icon in the format bar (or use the Ctrl+K keyboard shortcut).

    The title of your post asks for help with a "nested if" but I don't see one in the screenshot of your code.

    If all of your machine names are present in DNS, and there are corresponding PTR records for the IP addresses, then using the Resolve-DnsName cmdlet will return the name associated with the IP address.

    0 comments No comments

  2. Ian Xue 39,021 Reputation points Microsoft Vendor
    2021-03-01T07:55:19.553+00:00

    Hi,

    Not sure what you want the output to be like. If you don't want to add "not found" to the result then you don't add the pscustomobject to $obj when nothing is found.

    Best Regards,
    Ian Xue

    ============================================

    If the Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.