Issue: While running powershell in SQL job step, I am getting below error: –
A job step received an error at line 13 in a PowerShell script. The corresponding line is ‘Write-Host “ServerName: ” $comp’. Correct the script and reschedule the job. The error information returned by PowerShell is: ‘Cannot invoke this function because the current host does not implement it. ‘. Process Exit Code -1. The step failed.
Solution: SQL Server Agent allows users to directly run PowerShell scripts in SQL Server Agent. Internally this is implemented by reusing the SQLPS.EXE shell. When SQL Server Agent starts SQLPS.EXE, it does not do this through the console (there is no console attached).
When you run Write-Host, PowerShell asked to write on host console but due to no availability of HOST console, we got error.
I removed Write-Host to resolve issue.
Reference: Rohit Garg (http://mssqlfun.com/)
You can find and follow MSSQLFUN:-
Other Linked Profiles :-