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

Author Message
[View user's profile]

Joined: 2015-08-26
Posts: 2
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?
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 26890
Location: Prague, Czechia
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:
[View user's profile]

Joined: 2015-08-26
Posts: 2
That did it! Thank you so much. This makes my life much easier. Very Happy

You can post new topics in this forum


What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!


About donations

$9   $19   $49   $99

About donations


WinSCP Privacy Policy

WinSCP License