Hi everyone.
Could anyone offer my any advice on why this works when run in ISE but fails in SQL Agent job.
Script is :
$collection = $()
foreach ($server in get-content "C:\SQLSkills\PowerShell\All_SQL_Servers_Ping_names.txt")
{
$status = @{ "ServerName" = $server; "TimeStamp" = (Get-Date -f s) }
if (Test-Connection $server -Count 1 -ea 0 -Quiet)
{
$status["Results"] = "Up"
}
else
{
$status["Results"] = "Down"
}
New-Object -TypeName PSObject -Property $status -OutVariable serverStatus
$collection += $serverStatus}$collection | Out-File C:\SQLSkills\PowerShell\pingresults.csv
Works in ISE as I say but fails when run in agent job. Agent account has privs to do task. Error message I get is :
Message
Unable to start execution of step 1 (reason: line(1): Syntax error). The step failed.
Any help much appreciated.
Thanks