August 15, 2023 at 3:08 pm
I have a Powershell script which is being called through Windows Task Scheduler
My script is set up as follows:
param(
$FileDirectory,
$VerboseDirectory,
$ServerInstance,
$Database
)
Invoke-Sqlcmd -ServerInstance $ServerInstance -Database $Database -Query "EXEC spImportReturn @FileDirectory = '$FileDirectory'" -verbose 4> $VerboseDirectory
Now I then call this Powershell script from Windows Task Scheduler as follows:
Executable: %SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe
Add arguments (optional):
-File "C:\ChrisDev\PowershellScripts\MainPrograms.ps1"
-FileDirectory "C:\users\user1\DER\staging\returns\"
-VerboseDirectory "C:\Temp\DbAdmin\ImportDERReturn\ImportDErReturn.txt"
-ServerInstance LONSQL01\SQLEXPRESS
-Database "ReturnsDatabase"
However I am getting the following error :
Invoke-Sqlcmd : Cannot validate argument on parameter 'Database'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again. At C:\ChrisDev\PowershellScripts\MainPrograms.ps1:57 char:57
What am i doing wrong here?
August 16, 2023 at 1:56 am
Can you put double quotes around the -ServerInstance parameter value similar to other params?
=======================================================================
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply