Tuesday, June 9, 2015

Reading in a CSV file in Powershell

CSV files make my life a whole lot easier, especially with large numbers. If you have an excel file with a hostname and an IP address, you get a csvfile like:


You can import it with the following statement:

$csvfile = Import-Csv C:\Book2.csv

foreach ($value in $csvfile){

$hostname = $value.server

$IP = $value.IPAddress

Write-Host "do whatever here to $hostname with IP address: $IP"


No comments:

Post a Comment