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”
I would never have thought of that!
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
Microsoft really needs to work on their error messages. But thank you. I never would have thought of CLS being the problem.
Thank you so much. This really save me a lot of debugging time.
Thanks a lot 🙂
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!
Thanks .. this worked.. 🙂
You are a life saver, thanks very much for posting this. I was stuck with this – very ambiguous error for hours. Bless you.