How to setup Powershell script alarm action

I am trying to run the following powershell script from an alarm action:

[string]$Server = {{CONNECTION_NAME}}
[string]$Database = {{SQLFiles.DBName}}

[string]$qry = "
SELECT * FROM sys.database_files
ORDER BY type DESC"

$databaseFiles = Invoke-Sqlcmd -ServerInstance $Server -Database $Database -Query $qry

foreach($databaseFile in $databaseFiles){
$qry = "
DBCC SHRINKFILE ({0}, 1)
GO" -f $databaseFile.name

$Results = Invoke-Sqlcmd -ServerInstance $Server -Database $Database -Query $qry -QueryTimeout 0
}

But I am getting the following error:

Action 'Action/{1DAEF516-D18C-43B8-9F4B-6D66376B08B2}/RunPowerShellScriptOperation/tempdb.PRIMARY' failed : The term 'TPAPDBS13' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.At C:\Users\SVC_SQLAdministrator\AppData\Local\Temp\Spotlight13309656789683844005.ps1:2 char:1+ Invoke-Command -ComputerName TPAPDBS13 -authentication NegotiateWithI ...+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    + CategoryInfo          : ObjectNotFound: (TPAPDBS13:String) [], CommandNotFoundException    + FullyQualifiedErrorId : CommandNotFoundException    + PSComputerName        : TPAPDBS13  [1]

If I run this script in PowerShell with the $Server and $Database received as params, the script works.

Parents Reply Children
No Data