0

Use Powershell to download and parse a CSV

by Jim Bouse 30. August 2024 12:14

I needed to create directories for every "id" in a dynamic CSV from a webserver.

This required me to need to convert the CSV to a object then foreach through that object checking for the directory and creating it if it was not there.

foreach ($loc in ((Invoke-WebRequest -URI https://my.webserver.address/get_csv.php).Content |
ConvertFrom-Csv -Delimiter ",")) { 
  $path = ('C:\Shares\Pages\'+$loc.id); 
  if (!(test-path -PathType Container $path)){ 
    New-Item -ItemType Directory -Path $path 
  } 
}

Tags:

PowerShell

Powered by BlogEngine.NET 2.5.0.6
Original Design by Laptop Geek, Adapted by onesoft