Restrictions on some cmdlets to execute in a 'PowerShell Script' operation.

  • KM03631410
  • 31-Mar-2020
  • 19-May-2021

Summary

There are restrictions on some cmdlets to execute in a 'PowerShell Script' operation.

Question

A 'Library/Operations/PowerShell/PowerShell Script' operation in Base CP may fail when a cmdlet is executed. For example, it fails when Write-Host cmdlet is executed due to the following exception thrown by the PowerShell environment:

System.Management.Automation.RemoteException: A command that prompts the user failed because the host program or the command type does not support user interaction. Try a host program that supports user interaction, such as the Windows PowerShell Console or Windows PowerShell ISE, and remove prompt-related commands from command types that do not support user interaction, such as Windows PowerShell workflows.

Another example of an exception thrown when Clear-Host cmdlet is executed is:

System.Management.Automation.RemoteException: Exception setting "ForegroundColor": "Cannot convert null to type "System.ConsoleColor" due to invalid enumeration values. Specify one of the following enumeration values and try again. The possible enumeration values are "Black, DarkBlue, DarkGreen, DarkCyan, DarkRed, DarkMagenta, DarkYellow, Gray, DarkGray, Blue, Green, Cyan, Red, Magenta, Yellow, White"."

Answer

Such an exception can be thrown by the PowerShell environment when a cmdlet that requires user interaction and so a 'PowerShell Script' operation can fail due to it. In order to avoid it, such a cmdlet may need to be replaced or removed. For example, Write-Object can be used instead of Write-Host.