Applications Systems

SAM script that includes Windows PowerShell Monitor causes SetBufferContents exception

This article describes how to resolve an error with a script that uses the Windows PowerShell Monitor and results in a log message similar to "Exception calling "SetBufferContents" with "2" argument(s): "The 'SetBufferContents' member is not supported by ApmPsHostRawUserInterface." This issue may be related to the Clear-Host function.

First published date

12/23/2019 10:49 PM

Last published date

12/27/2019 4:00 PM

Overview

As described in the SAM Custom Template Guide, you can use the Windows PowerShell Monitor included in SAM to run custom PowerShell scripts that monitor Windows-based computers.

This article describes how to resolve an exception that may result in a log message similar to:
Exception calling "SetBufferContents" with "2" argument(s): "The 'SetBufferContents' member is not supported by ApmPsHostRawUserInterface.
See also Use PowerShell in SAM.

 

Product section

Server Application Monitor

Cause

This issue is caused by calling the Clear-Host method that removes all text from the current display, including commands and output that might have accumulated. When this PowerShell method is complete, it displays the command prompt. The issue may also be caused by the use of the following Clear-Host aliases:
  • cls
  • clear
  • [System.Console]::Clear();
This issue may also be related to ApmPsHostRawuserInterface, SAM's implementation of the PsHostRawUserInterface class that handles how PowerShell displays output. This implementation does not support the SetBufferContents method, so if you use that method explicitly in a script or if another function uses the method in its implementation, a NotSupported exception may occur.

Resolution

Remove the Clear-Host method from the script.

Do not use the following Clear-Host aliases:
  • cls
  • clear
  • [System.Console]::Clear();
If the issue continues, remove the SetBufferContents method.