Post a reply

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

DakotaPaul

That did it! Thank you so much. This makes my life much easier. :D
martin

Re: Powershell script from SQL Server Agent giving "'Add-Type' is not recognized" error

The Add-Type is supported since PowerShell 2.0.

Maybe your SQL server supports PowerShell 1.0 only.

You can use this method instead:
[Reflection.Assembly]::LoadFrom("WinSCPnet.dll") | Out-Null

See footnote at:
https://winscp.net/eng/docs/library_powershell#fn5
DakotaPaul

Powershell script from SQL Server Agent giving "'Add-Type' is not recognized" error

I adapted the WinSCP PowerShell example to upload a file and it works perfectly from powershell.exe. I then created an SQL Server Agent job to run this script but it's failing on the try-catch block with the error: "The term 'Add-Type' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again."

In my agent job step the Type is set to PowerShell and I just pasted the script from the .ps1 file that works from the command line. This is on SQL Server 2008 R8. Has anyone seen this before?