T
T
tartarelin2018-06-01 15:40:32
PowerShell
tartarelin, 2018-06-01 15:40:32

Why is powershell script not executing with scheduler?

There is a small script, something like this:

copies all images from one folder to another

$source = 'd:\1С Files\20180601'
$dest = '\\srv-data\foto\20180601'
$include = @('*.png','*.jpg','*.gif')
$files_on_SQSTALFA = Get-ChildItem $source -Recurse -Include $include
foreach ( $item in $files_on_SQSTALFA ) {
$file_on_srvdata = Join-Path $dest $item.FullName.Substring($source.length)
if ((Get-FileHash -Algorithm MD5 -Path $item).Hash -ne (Get-FileHash -Algorithm MD5 -Path $file_on_srvdata).Hash)
{
New-Item -ItemType File -Path $file_on_srvdata -Force
Copy-Item -Path $item -Destination $file_on_srvdata -Force
}
}

If you run it from a domain user in PowerShell ISE, then it works as it should, if you make a task in the scheduler and run it from a domain user, it does not work, the status constantly shows how it "works", but the script does not actually start.
What could be the secret?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
tartarelin, 2018-06-29
@tartarelin

Idiot mistake, I didn’t put powershell scripts in the scheduler for so long that I forgot how to do it, instead of running powershell and the script in it, I immediately launched the script as a bat file

L
LoGIc89, 2018-06-04
@LoGIc89

Does the task run as "Hidden Task" ?
If yes, then uncheck the box so that the console window starts at startup.
In it you will see errors during execution. If a task says "Running" for a long time, it might actually be running, it just can't do what is asked of it.
The second option is to redirect the error output to a file.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question