Hi,Wondering if anyone has any ideas what might be happening here. I've set up a SQL Server Agent Job that has a Powershell step in it. The job keeps failing when it tries to execute the Powershell script. Here's the Powershell script:[code]$dbName = "MyTest"# Get current date[datetime] $date = Get-Date# Get CSV file properties$filePath = "C:\Test Folder\"$fileName = "TestFile"#_YYYY_MM_DD" -replace "<<YYYY_MM_DD>>", $date.ToString("yyyy_MM_dd")$fileNameExtension = "csv"$headerRow = "COLUMN1, COLUMN2, COLUMN3"$path = $filePath + $fileName + "." + $fileNameExtension# Create CSV file and append header rows$fso = new-object -comobject scripting.filesystemobject$file = $fso.CreateTextFile($path,$true)$file.WriteLine($headerRow)# Call stored procedure and append rows to CSV file$sql = "DECLARE @FirstDayOfPreviousMonth AS DATE = CAST(DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE())-1, 0) AS DATE) EXEC MyTestSproc @FirstDayOfPreviousMonth "Invoke-SqlCmd -database $dbName -Query $sql | ForEach-Object { $file.WriteLine( $_[0].ToString() + "," + $_[1].ToString() + "," + $_[2].ToString() ) }$file.close()[/code]Here's the error I'm receiving:[code]A job step received an error at line 17 in a PowerShell script. The corresponding line is '$file = $fso.CreateTextFile($path,$true)'. Correct the script and reschedule the job. The error information returned by PowerShell is: 'Exception calling "CreateTextFile" with "2" argument(s): "Exception from HRESULT: 0x800A004C (CTL_E_PATHNOTFOUND" '.[/code]I've verified that C:\Test Folder\ exists both in my local C: as well as the C: on the server hosting the databases, yet neither of them is getting recognized by the job. I'm quite new to PowerShell and I'm probably missing something pretty obvious. Any ideas?
↧