从url下载exe

时间:2018-01-29 18:50:45

标签: powershell

我想下载网站上找到的最新xdat.exe

https://www.mcafee.com/apps/downloads/security-updates/security-updates.aspx 

但我不能。我收到错误消息:

  

" System.Object []"在类型" System.Uri"中,参数" Uri"需要。不支持指定的方法。

任何人都知道为什么?

    $destfolder = "C:\Users\test\Desktop\MCAFEE $((Get-Date).ToString('dd-MM-yyyy'))"
    If(!(test-path $destfolder))
    {
          New-Item -ItemType Directory -Force -Path $destfolder
    }

    $urlrootpath = "https://www.mcafee.com/apps/downloads/security-updates/security-updates.aspx"      
    $dest = "$destfolder\xdat.exe"
    $definitionPath = (Invoke-WebRequest $urlrootpath).Links |
        Where-Object{$_.InnerText -like "*xdat.exe"} |
        Select-Object -ExpandProperty href
    ForEach-Object -Process { 
       try {  
           Invoke-WebRequest -Uri $definitionPath -OutFile $dest
       } catch {            
           Write-Warning -Message "ERROR : $($_.Exception.Message)"            
       }            
    }

2 个答案:

答案 0 :(得分:0)

如果我运行此$definitionPath为空。可能,因为您首先必须接受许可协议,才能看到页面上的下载链接。但是,您可以从http://download.nai.com/products/datfiles/V3DAThttp://download.nai.com/products/licensed/superdat/english/intel访问下载。

同样Foreach-Object要求InputObject生效。目前还有非。添加参数-InputObject $definitionPath或在上一行中添加|,并将$definitionPath替换为$_ ScriptBlock中的-Process

答案 1 :(得分:-1)

最后我发现了如何做到这一点,唯一的问题是它需要我3个.exe文件,我想要最新的文件......是否有可能?

$urlrootpath = "http://download.nai.com/products/licensed/superdat/nai/French/"       
$definitionPath = (Invoke-WebRequest $urlrootpath).Links |
    Where-Object{$_.InnerText -like "*xdat.exe"} |
    Select-Object -ExpandProperty href |
ForEach-Object -Process { 
   try {  
       $dest = "$destfolder\$_" 
       Invoke-WebRequest -Uri $urlrootpath/$_ -OutFile $dest
   } catch {            
       Write-Warning -Message "ERROR : $($_.Exception.Message)"            
   }            
}