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 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy