I have a simple PowerShell script that runs fine from the console (PSVersion 2.0).
$psftpPath = "C:\Program Files (x86)\PuTTY\psftp.exe"
$sftpHost = "foo.baa.com"
$userName = "myusername"
$userPassword = "mypassword"
$todate = Get-Date -format yyMMdd;
$fromdate = (get-date).AddDays(-7).ToString("yyyMMdd")
$filename = "RawData_Extract_$($fromdate)_$($todate).zip"
$cmd = @("lcd D:\Healthstream", "get $($filename)", "bye")
$cmd | & $psftpPath -pw $userPassword "$userName@$sftpHost"
I want to schedule it as a SQL Server Scheduled Job. When I set the "Type:" of job to PowerShell it fails with a Syntax Error on (or around) the $cmd line (line 9).
Can anyone help me understand what I'm doing wrong?