We've recently upgraded to SQL Server 2012 (from SQL Server 2008 R2) on Windows Server 2012 (from Windows Server 2008 R2), and a SQL Server Job Agent job that was previously running without error is now failing.
The job has a Powershell job step:
$ErrorActionPreference = 'Stop'
$DateStamp = Get-Date -format "yyyyMMdd"
$BizUnit = 'SHB'
# Target File directory
$BaseDir = '\\MyFileServer\MyDirectory'
$Query = "EXEC dbo.usp_MyQuery '$BizUnit'"
$TargetFile = "MyTargetFile_" + $BizUnit + "_$DateStamp.xml"
$TargetDir = (Join-Path -Path $BaseDir -ChildPath $BizUnit)
$Query | Out-File -FilePath (Join-Path -Path $TargetDir -ChildPath $TargetFile) -Force -Encoding "utf8"
When the job is run, it fails with this error message:
A job step received an error at line 14 in a PowerShell script. The corresponding line is '$Query | Out-File -FilePath (Join-Path -Path $TargetDir -ChildPath $TargetFile) -Force -Encoding "utf8"'. Correct the script and reschedule the job. The error information returned by PowerShell is: 'Cannot perform operation because operation "ReportWrongProviderType" is invalid. Remove operation "ReportWrongProviderType", or investigate why it is not valid.
I can't find any references to "ReportWrongProviderType" when I search the interwebz. Any ideas on what is wrong with the Out-File call?
A job step received an error at line 28 in a PowerShell script. The corresponding line is ' throw $e'. Correct the script and reschedule the job. The error information returned by PowerShell is: 'System.Management.Automation.CmdletInvocationException: Cannot open file because the current provider (SqlServer) cannot open a file.
The account running the job has Full Control of the target directory. Perhaps there is a missing permission that would allow Powershell to act on a file share in Win2012?