Skip to content

November 1, 2011


ConsoleColor error in Powershell job step in Sql Server

by Scott Newman

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"."  ‘.

Read more from Powershell, SQL Server
11 Comments Post a comment
  1. Sep 28 2012


  2. Jan 8 2013

    I would never have thought of that!
    Many thanks

  3. Apr 15 2013


  4. Ashish C
    Sep 4 2013

    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

  5. May 3 2016

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

  6. Erik
    Jun 1 2016

    Thank you so much. This really save me a lot of debugging time.

  7. Jul 27 2016

    Thanks a lot ๐Ÿ™‚

  8. Jon of All Trades
    Dec 12 2016

    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!

  9. Dec 21 2017

    Thank you!!!

  10. Shraddha
    Jun 12 2018

    Thanks .. this worked.. ๐Ÿ™‚


Leave a Reply

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

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

Google photo

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

Twitter picture

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

Facebook photo

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

Connecting to %s

Note: HTML is allowed. Your email address will never be published.

Subscribe to comments

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

%d bloggers like this: