Need help with nested if else

Maheswar Reddy 1 Reputation point

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,451 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Rich Matheisen 45,671 Reputation points

    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 (Shanghai Wicresoft Co., Ltd.) 34,111 Reputation points Microsoft Vendor


    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