ConsoleColor error in Powershell job step in Sql Server

If you see an error like this when you execute a powershell job in sql server, it is due to an errant cls in your powershell script.  Remove the cls and it should execute correctly.  There is no screen to clear, hence it errors out.

A job step received an error at line 3 in a PowerShell script. The corresponding line is ‘$space.ForegroundColor = $host.ui.rawui.ForegroundColor’. Correct the script and reschedule the job. The error information returned by PowerShell is: ‘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"."  ‘.

12 thoughts on “ConsoleColor error in Powershell job step in Sql Server

  1. Thank you so so so much..I modified complete program and rewrote all functions except clear-host. Finally googled and found life saving tip..thank you again

  2. Microsoft really needs to work on their error messages. But thank you. I never would have thought of CLS being the problem.

  3. I’m quite certain that your blog just saved me an hour of troubleshooting and perhaps the rest of my hair. Thank you for sharing what you know!

  4. You are a life saver, thanks very much for posting this. I was stuck with this – very ambiguous error for hours. Bless you.

Leave a Reply to Ashish C Cancel reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.