I have a powershell script that download an antivirus update daily. When i execute the script manually, it works perfectly, but in the Scheduled task doesnt work. Only opens the .ps file that contains the code of the script (It opens in notepad). I dont know whats happening. This is the script:

remove-item E:\Update\* -Recurse
#Proxy auth
$WebProxy = New-Object

$client = new-object System.Net.WebClient
$client.proxy.Credentials = New-Object
System.Net.NetworkCredential($Username, $Password)
$client.DownloadFile($url, "E:\Update\Daily_Update.zip")
Set-Location E:\Update\ 
$Unzip = New-Object -ComObject Shell.Application
$FileName = "Daily_Update.zip" 
$ZipFile = $Unzip.NameSpace((Get-Location).Path + "\$FileName") 
$Destination = $Unzip.namespace((Get-Location).Path) 
  • Do you have notepad configured to open .ps files? – DavidPostill Mar 12 '18 at 15:14
  • In Actions you should choose action start program in program you write PowerShell.exe and in Arguments you write -File "C:\path\script.ps1" then it should get executed via PowerShell – SimonS Mar 12 '18 at 15:15
  • What anti-virus are you using that can't update automatically? – HackSlash Mar 12 '18 at 15:33
  • 1
    I live in Cuba, we dont access to internet like you. – Daril Alemán Mar 13 '18 at 12:17
  • @DarilAlemán I lol'ed a bit at that. – SimonS Mar 13 '18 at 12:54

Here are the settings you need:

Action: Start a program

Program/script: Powershell.exe

Add arguments: -ExecutionPolicy Bypass -FILE "C:\path\script.ps1"

EXAMPLE: https://community.spiceworks.com/how_to/17736-run-powershell-scripts-from-task-scheduler

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.