Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

PowerShell script doesn't work in Task Scheduler in Windows Server 2016

$
0
0

1) I have seen a lot of topics like that, but don't find the solution.

I need to start powersheel script every 5 minutes from Administrator with highest privileges:

Action is 

Start program

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe

-File "C:\Work\ConvertAndUpload.ps1"

In the history - task has been done. But I see that script have not been work. Screenshot from history:

2) As a second way to do this i have tried to create .bat file with start this powershell script and start this .bat from Task Scheduler. It doesn't work too (without errors, just ps-script not really starting).

3) I have tried to create new task from powershell console (to do from SYSTEM):

It is working without errors too, but still doesn't really do powersheel script.

Powershell script is very easy - it converts .xls file to .csv and send it ftp. Code of this script:

$source = 'C:\Work\Test'

Function ExcelCSV ($File)
{
    $Excel = New-Object -ComObject Excel.Application
    $Excel.Visible = $false
    $Excel.DisplayAlerts = $false
    $wb = $Excel.Workbooks.Open($File.FullName)

foreach ($ws in $wb.Worksheets)
        {
        $ws.SaveAs(($Files.FullName -replace ".xls$","") + ".csv", 6)
        }
        $wb = $Excel.Workbooks.Close()
        $Excel.Quit()
}

 Foreach ($Files in (Get-ChildItem -Path $source -Filter "*.xls"))
{
    ExcelCSV($Files)
}
$FileToUpload = "C:\Work\Test\test.csv"
$ftp = 'ftp://login:password@ftpaddress:2225/test.csv'
$webclient = New-Object System.Net.WebClient
$uri = New-Object System.Uri($ftp)

Please, help, I just don't know what to do more.

P.S. It is new account here, so I can't contain images in body, so I will try put them in comments.


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>