Hey everyone, it’s been a little while since my last post, but work’s been busy. A recurring issue I see on TechNet is that plenty of people have trouble working with importing/exporting CSV files. Specifically, I see questions about how to modify CSV files. Personally, I don’t see any value in modifying the CSV file directly, but rather importing the data from said file and working with the dataset natively in PowerShell. Using one person’s thread as an example, he had a CSV file full of IP addresses that corresponded to his VM’s. He wanted to add data about the VM based on the IP address, but wanted to know how to “modify the line” in the CSV file. He had already written part of the script to create the CSV by pinging each computer in his IP range and outputting that to CSV. For our test, here’s what our CSV looks like:
Now, let’s say we want to find the hostnames for each of these computers and add that to a new column. There are a couple ways we could do this, but in an enterprise environment, a good way to do it is to just ask AD who it is. First, we create the empty “column” for our Hostname value.
Once that’s created, we need to fill it with values: