0

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
$Username="daril.aleman"
$Password="MyPassword"
$WebProxy = New-Object
System.Net.WebProxy("http://proxy.example.com:3128",$true)
$url="The.url.of.download.com/file.zip"

$client = new-object System.Net.WebClient
$client.Proxy=$Webproxy 
$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) 
$Destination.Copyhere($ZipFile.items())
6
  • Do you have notepad configured to open .ps files?
    – DavidPostill
    Commented Mar 12, 2018 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
    Commented Mar 12, 2018 at 15:15
  • What anti-virus are you using that can't update automatically?
    – HackSlash
    Commented Mar 12, 2018 at 15:33
  • 1
    I live in Cuba, we dont access to internet like you. Commented Mar 13, 2018 at 12:17
  • @DarilAlemán I lol'ed a bit at that.
    – SimonS
    Commented Mar 13, 2018 at 12:54

1 Answer 1

2

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .