Running ps script from task scheduler

I have the following script:

$sqlServerNames = "computername"
[Array]$Collection = foreach ($sqlServerName in $sqlServerNames) {
    $sqlServer = New-Object Microsoft.SqlServer.Management.Smo.Server($sqlServerName)

    foreach ($job in $sqlServer.JobServer.Jobs) {
        $job | Select-Object Name, OriginatingServer, OwnerLoginName, IsEnabled, LastRunDate, LastRunOutcome, DateCReated, DateLastModified, NextRunDate
    $Collection += $job
$Collection | Export-CSV "\\computername\c$\\sqljobs.csv" -force –noType -Encoding:UTF8

When i run this in powershell, I’ve no problems. However when i run via task scheduler with admin rights with the following parameters: -NoLogo -NonInteractive -File “\computername\c$\Powershell\SF3.ps1”
The csv file just comes up blank.

Any ideas? Thank you.

Stab-in-the-dark theory: The credentials used to run the scheduled task do not have login permissions to the SQL Server instance and the script fails to return any data.

Do you use the same credentials for the scheduled task as you use to run the script manually?

Yep, you’re right. That’s great, thank you!
Not sure how I didn’t see that.