PowerShell Schedule Task

Handian Sudianto 5,121 Reputation points
2024-10-03T02:44:58.6966667+00:00

Hello,

I have powershell script to insert some data into SQL server, when i double click on the .ps1 file i can see the data in SQL server.

Then i want to make this script running every hours and i schedule this using windows task scheduler.

But unfortunately when this scrip running as schedule, the task schedule log say the script running successfully but i cannot see any data in the SQL server. Anyone know why?

User's image

User's image

Windows Server
Windows Server
A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.
13,206 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,547 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Christopher Bliss 75 Reputation points
    2024-10-13T10:58:34.4133333+00:00

    Handian,

    Like Rich's comment mentioned, I would verify the account used to run the task has the proper permissions to SQL and the folder path listed. Also, the argument list for your task may need to look a little something like the below.

    "& 'D:\SFTP_Root\Script-Insert-Backup-To-DB.ps1'"

    This means your Details column should look like the below.

    powershell.exe "& 'D:\SFTP_Root\Script-Insert-Backup-To-DB.ps1'"

    Let me know if that ended up helping out!

    Regards,

    Christopher

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.