I am having a very difficult time doing something that seems very simple. I have created a powershell script that simply moves the backup files in the default SQL backup directory to a different directory. I cannot get the script to execute.
I have created an Agent Job, with the type: "Operating system (CmdExec)"
For the command, i have tried the following:
powershell "I:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\Test.ps1"
--Error = "The term 'I:\Program' is not recognized as the name of a cmdlet, function, script file..."
"powershell I:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\Test.ps1"
--Error = "The system cannot find the file specified
'powershell I:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\Test.ps1'
--No Error, but the script path is simply echoed back. The script does not actually execute
powershell "I:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\Test.ps1"
--Error = "The term 'I:\Program' is not recognized as the name of a cmdlet, function, script file..."
powershell I:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\Test.ps1
--Error = "The term 'I:\Program' is not recognized as the name of a cmdlet, function, script file..."
So as you can see, I have tried several combinations of both single and double quotes. I am certain that the script is not even executing, as I tried a test script that simply echos "Hello World" and i get the same results.
I have SQL Server 2008 R2 with SP2 and PowerShell Version 2.0
So what is the secret to running PowerShell scripts from a SQL Agent Job?
Thanks