R
R
Roman Ratkin2019-02-07 19:28:10
PowerShell
Roman Ratkin, 2019-02-07 19:28:10

Why is copying not performed when the script is executed by the scheduler?

Good day to all!
Tell me, there is a simple script. He makes a backup of the database and copies it over the network. If you execute the script manually, then everything is fine. But, the task in the Task Scheduler does not process copying. If you execute the script from the user specified in the scheduler, then the script also works from him. Where to dig?
Script:

$DB = "sa"
$CurrentDate = Get-Date -Format yyyy-MM-dd
$SQLPath = "SQLSERVER:\sql\S002\DEFAULT\DATABASES"
$BackupPath = "H:\backup\"
$BackupFile = "H:\backup\${CurrentDate}_$DB.bak"
$DestinationPath = "\\s015\bkup\"


import-module sqlps -DisableNameChecking

Backup-SqlDatabase -Path $SQLPath -Database $DB -BackupFile $BackupFile

Copy-Item $BackupFile $DestinationPath

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan, 2019-02-07
@GeraIV

If everything works when you specify an account, it's probably a matter of rights. Try redirecting the copy output to a file and see what's there.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question