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())
Actions
you should choose actionstart program
in program you writePowerShell.exe
and in Arguments you write-File "C:\path\script.ps1"
then it should get executed via PowerShell