Home » SQL Server » System.ConsoleColor error while running powershell in SQL agent job step

System.ConsoleColor error while running powershell in SQL agent job step

Issue: While running powershell in SQL agent job step, I am getting below error: –

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"." ‘. Process Exit Code -1. The step failed.

Solution: This error occurs while you are using clear screen option in script part of SQL agent job step. Please check your script and remove cls or clear-host keywords.

I removed it and it start working fine.

Reference: Rohit Garg (http://mssqlfun.com/)

You can find and follow MSSQLFUN:-

http://www.facebook.com/mssqlfun

http://mssqlfun.com/feed

https://twitter.com/Rgarg86

Other Linked Profiles :-

http://social.msdn.microsoft.com/Profile/rohitgarg

http://www.sqlservercentral.com/blogs/mssqlfun/

http://www.toadworld.com/members/rohit-garg/blogs/default.aspx

http://beyondrelational.com/members/RohitGarg/default.asp

Leave a Reply

Join us on Facebook

microsoftcommunitycontributor
%d bloggers like this: