Powershell Reportwrongprovidertype is not valid?

89 Views Asked by At
Write-Host  "Script"

Write-Host "Execute on [$Sever].[$DatabaseN] on $Date"

$Server = "servername"

$DatabaseN =  "name"

$Date = Get-Date -format "yyyy-MM-dd"

      #$Enviroment= "enviroment"

$Enviroment = " eviroment e"

     #$Enviroment = "enviroment"

$SystemProvider = "Microsoft.PowerShell.Core\FileSystem"

$extportfolder = "folder\path"

$Destination = "$SystemProvider ::$exportfolder\$Enviroment"

Write-Host ""

##comment

Write-Host "infotmation"

$Query = Invoke-Sqlcmd -query "select max(id) high from table1 where reason no like '%fail%'" -serverinstance $Server -database $DatabaseN

$Id = $Query.Item("high")

$Output = "$Date - file-$Id.csv"

Write-Host ""

Write-Host "information"

$DataQuery = Invoke-Sqlcmd -query "EXEC [dbo].[outputfile]" -serverinstance $Server -database $DatabaseN

Write-Host ""

Write-Host "information" 

$DataQuery | Export-Csv $Output -notypeinformation -Force

Write-Host ""

Write-Host "information" 

Move-Item -path $Output -Destination $Destination -Force 

Write-Host " Export file = $Id on Server $Server successfully on $Date"

Error in $DataQuery | Export-Csv $Output -notypeinformation -Force:

path does not exist cannot perform operation because Reportwrongprovidertype is not valid

I dont know why is this error for?

I am trying to Output a csv file to a path using today's date and the last id from the query as the name and inside the file the results of the exec query.

The query runs successfully when using PowerShell ISE but not when running through the sql agent job

0

There are 0 best solutions below