Script work but not as a windows task

hello everyone,
my works fine if i manually start it.

But in need to plan it over the windows task.
this does not work for the complete script.

In the first step my script print all *.pdf files form a folder. (Works manually and in task)
Second step, the *.pdf should paste in a restore folder. (Works manually but not in task)

I don’t find the error for this … maybe someone can help me please?


My Code looks like this:

# Path to folder with pdf-Documents</em>
$files = gci "$tpath*.pdf"</em>
$files | %{&'C:\Program Files (x86)\SumatraPDF\sumatrapdf.exe' -print-to "Büro-1" "`"$($_.Fullname)`""}</em>
#$files | %{&'C:\Program Files (x86)\SumatraPDF\sumatrapdf.exe' -print-to "Brother HL-L8350CDW – Farbe" "`"$($_.Fullname)`""}</em>
#-Archiv / Resotre folder------------------------------------------------------------</em>
foreach($item in (Get-ChildItem -Path "$tpath" | Where-Object {$_.Name -like "*.pdf*"}))</em>
Move-Item -Path $item.FullName -Destination ("$tpath\Archiv\"+$(Get-Date).ToString("yyyy-MM-dd-HH-mm-ss-")+$($item.Name))</em>
}</em><span data-mce-type="bookmark" style="display: inline-block; width: 0px; overflow: hidden; line-height: 0;" class="mce_SELRES_start"></span>
  • What type of user are you running this task? System user? Domain user?
  • Does the user you are running the task as have permission to the destination folder?
Getting the error from the Move-Item would be helpful. Maybe adding Start-Transcript and Stop-Transcript so we can see the error. Start-Transcript has a -Path parameter so you can log the console output if there is an error when running the Move-Item section of your script.


Thx for the tipps.

I implementated the logging function and so i found out that it was a permission problem.
The loggin works just for the directly start over powershell.

I switch to the admin user and set the rights new for this folder and sub folders.

Now it works!

Thx a lot pwshliquori :slight_smile: