![](/img/trans.png)
[英]unable to run sharepoint powershell script from sql server agent job
[英]SQL Server Agent Job is not invoking Powershell Script
我有 Powershell 將 XLS 文件轉換為 CSV 文件的腳本。 如果我手動運行此腳本,它工作正常,但它不適用於 SQL 服務器代理作業。 SQL 服務器代理作業未拋出任何錯誤,但腳本也未執行任何操作,因為它未將 XLS 文件轉換為 CSV。
Powershell腳本代碼(Convert2CSV.ps1)
$Dir="C:\Source\TEST\Deployment\ReportOutput"
$Files =Get-Childitem $Dir -filter "*.xls"
foreach ($file in $Files)
{
$excelFile = "$Dir\"+$File
$Excel = New-Object -ComObject Excel.Application
$wb = $Excel.Workbooks.Open($excelFile)
foreach ($ws in $wb.Worksheets)
{
$ws.SaveAs($excelFile.Replace(".xls","") + ".csv", 6)
}
$Excel.Quit()
}
下面是機器上的 Powershell ExecutionPolicy。 Sql服務器和Powershell腳本在同一台機器上
PowerShell 腳本中沒有錯誤處理,因此無論如何您都很難完全調試它。
由於它從 SQL Agent 失敗,因此我懷疑它已關閉服務帳戶和權限。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.