PowerShell là công cụ tự động hóa tác vụ miễn phí của Microsoft, giúp quản lý và tự động hóa tác vụ trên Windows. Nhưng không chỉ vậy.
Bạn cũng có thể tải file từ internet nhờ PowerShell. Bài này giới thiệu phương pháp đơn giản nhất. Bắt đầu nào!
Cách tải file với PowerShell
Cách phổ biến nhất: dùng URL của file cần tải. Sử dụng cmdlet Invoke-WebRequest.
Trước khi tải, cần chỉ định đích lưu file bằng tham số -OutFile.
Cú pháp hoàn chỉnh:
Invoke-WebRequest -Uri <source> -OutFile <destination>
Thay source bằng URL file, destination bằng đường dẫn lưu.
Sau khi mở PowerShell, gõ lệnh mẫu:
# Vị trí file nguồn $source = 'https://www.majorgeeks.com/files/details/4diskclean_free.html/4dskcln.exe' # Đích lưu file $destination = 'C:\programfiles\newfolder' # Tải file Invoke-WebRequest -Uri $source -OutFile $destination
Lệnh tải file từ URL nguồn và lưu vào C:\programfiles\newfolder.
Nếu cần đăng nhập trước khi tải, thêm tham số -Credential:
$credential = Get-Credential
Lệnh hoàn chỉnh:
$credential = Get-Credential $source = 'https://www.majorgeeks.com/files/details/4diskclean_free.html/4dskcln.exe' $destination = 'C:\programfiles\newfolder' Invoke-WebRequest -Uri $source -OutFile $destination -Credential $credential
Tải sẽ bắt đầu.
Tải file với PowerShell không rắc rối
Với phương pháp trên, tải file qua PowerShell khá đơn giản. Nhưng đừng dừng lại — PowerShell có hàng tấn cmdlet giúp làm gần như mọi thứ trên PC. Hãy tiếp tục khám phá!