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

Author Message
DakotaPaul
[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?
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24995
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:
https://winscp.net/eng/docs/library_powershell#fn5
DakotaPaul
[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
Advertisements

You can post new topics in this forum






Search Site

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!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License