2.9 Troubleshooting Configuration Errors

This section provides solutions for PowerShell error messages you may encounter.

2.9.1 PowerShell Execution Errors

Knowledge Scripts in the SharePoint category may raise events such as "PowerShell script failed to run to completion" or "Error executing PowerShell script." These errors can occur when Knowledge Scripts take a long time to run, or when there is contention for access to the server that executes the PowerShell scripts, MCPSHostServer.exe. The following are some recommendations for resolving these issues:

  • Increase the amount of memory that can be used by MCPSHostServer.exe. Increasing the memory limit reduces the frequency with which the server restarts due to excessive memory usage. Increasing the memory limit also reduces the number of PowerShell errors; each time the server recognizes that it is exceeding its memory usage threshold, the server prevents new jobs from executing until all existing jobs have completed and the server restarts. If existing jobs take a significant amount of time to complete, the waiting jobs may time out and return errors. To increase the amount of memory MCPSHostServer.exe can use, modify the value of the maxMemoryUsage setting. For more information, see Section 2.7, Changing PowerShell Configuration Settings.

  • Increase the number of PowerShell execution environments, or runspaces, that MCPSHostServer.exe can host. If you attempt to run more jobs than the available number of runspaces on the server, the most recent jobs are held back until runspaces become available as existing jobs complete their iterations. Being held back in this manner increases the chance that jobs will time out before running or before completing their iteration. To increase the number of available runspaces, modify the maxActiveClients setting. For more information, see Section 2.7, Changing PowerShell Configuration Settings.

    NOTE:The client’s maxActiveServers configuration option specifies the maximum number of servers that can be active at any time (the default is five). The maxActiveServers configuration value and the maxActiveClients server configuration value determine the total number of jobs that can be serviced at any one time. You can have more than this number of jobs in the “Running” state in AppManager, but only if some of the jobs are between iterations, and not actually running at the same time.

2.9.2 PowerShell Initialization Error

Knowledge Scripts in the SharePoint category may also raise events such as "Failed to initialize MCPSHostServer PowerShell session."

The following settings in the server configuration file, MCPSHostServer.exe.config, determine the number of MCPSHostServers running:

  • maxActiveServers

  • maxActiveClients

  • maxMemoryUsage

When a job runs, the client, MCPSHostClient, checks if there is a server that does not already have the maximum number of jobs running (maxActiveClients), and is not in shutdown mode because of exceeding its maximum amount of memory (maxMemoryUsage). If there is a server that meets the criteria, the client uses that server to run the job.

If no server meets the criteria, the client checks whether the maximum number of MSPSHostServer.exe instances (maxActiveServers) is already running. If it is not, the client starts a new server and submits the job to that server. If the maximum number of instances (maxActiveServers) is already running, and all instances have the maximum number of jobs running (maxActiveClients), then the client holds the job until a server becomes available.

To resolve a PowerShell initialization issue, you can modify maxActiveServers, maxActiveClients, and maxMemoryUsage. For example, by raising the values of maxMemoryUsage and maxActiveClients, you are allowing many clients to run on a single server. In that case, you can decrease the value of maxActiveServers. For more information about these settings, see Section 2.7, Changing PowerShell Configuration Settings.