What is wrong with my PS Script?

David Orlow 1 Reputation point

Ok, for starters, can you tell me if what I'm trying to do makes any sense?
I have a request from one of our sites. They were relaying SMTP email off our Exchange server. They now have a new SMTP server and they think they've pointed every device to the new SMTP server. But, they wanted me to check to make sure they didn't miss any devices.

So, I did some research and the directories in the attached image are where I think I should find the IP addresses. I did have the script working once. To be honest, I don't know what changed to where it is throwing all the errors now. All I did was open one of the text files in one of the directories and found an IP address that I knew for sure was there, so, if my script was working correctly, it should find it, verifying the logic at least works.

But now the script is throwing errors and I'm not sure why.

I'm not sure why it's only hitting the first get-childitem and then skips to the next server in the array and only checks the first get-childitem again.



Exchange Server Management
Exchange Server Management
Exchange Server: A family of Microsoft client/server messaging and collaboration software.Management: The act or process of organizing, handling, directing or controlling something.
7,341 questions
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,359 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Andreas Baumgarten 96,036 Reputation points MVP

    Are there subfolders in the path of the Get-Childitem? If so maybe that is the issue because next is Get-Content and I am not sure if Get-Content is able to handle "folders".

    To get only files an not any subfolder object maybe this works (not tested!)

    Get-ChildItem "C:\Temp\" -Attribute !Directory  -Recurse 

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Andreas Baumgarten

  2. Rich Matheisen 44,776 Reputation points

    It's possible that you've just run out of memory on the remote machine. SMTP protocol logs can produce a lot of data! Run this on the remote machine:

    Get-Item WSMan:\localhost\Shell\MaxMemoryPerShellMB

    If the value is very low (say, 25), you can change it (replace %VALUE% with the new value):

    Set-Item WSMan:\localhost\Shell\MaxMemoryPerShellMB %VALUE% -Force

    On Windows 10 the value is 2147483647.

    0 comments No comments

  3. Yuki Sun-MSFT 40,856 Reputation points

    @David Orlow ,

    Based on my research regarding the error you shared, it also appears to me that it could be related to the MaxMemoryPerShellMB setting. Please have a go by modifying the setting to a higher value as suggested by RichMatheisen-8856, then run your PS script again and check how it goes.

    Here's a link about the error in your last image for your reference:
    The WSMan provider host process did not return a proper response
    Please Note: Since the web site is not hosted by Microsoft, the link may change without notice. Microsoft does not guarantee the accuracy of this information.

    If an 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.