Download for each object in txt file

Viewed 46

Idea is to open text file and each object inside will go to $root= 'https://website/plugin.cs' and download each file from website for each entry in the txt file

Where root will just be 'https://website/` and then each object will be appended at the end and downloaded

plugins.txt

plugin.cs
plugin6.cs
plugin2.cs
plugin3.cs

I am stuck

$plugins= 'C:\plugins.txt'

$root= 'https://website/plugins/'

Get-Content C:\plugins.txt | ForEach-Object { Invoke-WebRequest C:\Users\Downloads\test}
1 Answers

Use $_ to refer to the current input value inside the ForEach-Object scriptblock:

Get-Content $plugins | ForEach-Object {
    Invoke-WebRequest "$root/$_" -OutFile "C:\Users\Downloads\test\$_"
}
Related