2017-08-03 14 views
5

Điều tôi đang làm là chạy nó và nó sẽ trả về trang web và nó là một phần mềm không tải. Khi nó xuất hiện, tôi được nhắc nhở để lưu nó. Tôi đã tự hỏi làm thế nào tôi có thể viết mã để tự động lưu tập tin này? enter image description hereTự động lưu trong Powershell

$URL = "http://ps2pw027012/Reports/Reserved.ReportViewerWebControl.axd?ReportSession=bc5nij45tlov50byl2dsxgqk&Culture=1033&CultureOverrides=False&UICulture=9&UICultureOverrides=Fal 
se&ReportStack=1&ControlID=31a059a77a994ddc9f56f61d81f64615&OpType=Export&FileName=Local+Group+Members&ContentDisposition=OnlyHtmlInline&Format=CSV" 
$ie = New-Object -com internetexplorer.application; 
$ie.visible = $true; 
$ie.Navigate($URL); 
while ($ie.Busy -eq $true) { Start-Sleep -Seconds 100; } #wait for browser idle 

Trả lời

7

Bạn có một vài tùy chọn để thực hiện việc này. Bạn không thực sự cần phải sử dụng một đối tượng trình duyệt để tải xuống một tệp. Đây là một trang web tuyệt vời về cách tải file sử dụng Powershell, Use PowerShell to download a file with HTTP, HTTPS, and FTP

PowerShell 3 và sau:

Invoke-WebRequest -Uri "https://www.contoso.com/file" -OutFile "C:\path\file" 

Powershell 2 có cách này các tập tin tải về:

$WebClient = New-Object System.Net.WebClient 
$WebClient.DownloadFile("https://www.contoso.com/file","C:\path\file") 

Liên kết ở trên đi chi tiết hơn về nhiều cách tải xuống và lưu tệp thông qua các phương pháp khác nhau.

Các vấn đề liên quan