Add A Column To A CSV Using PowerShell

Say you have a CSV file full of awesome, super great, amazing information. It’s perfect, except it’s missing a column. Luckily, you can use Select-Object along with the other CSV cmdlets to add a column.

In our example, let’s say that you have a CSV with two columns “ComputerName” and “IPAddress” and you want to add a column for “Port3389Open” to see if the port for RDP is open or not. It’s only a few lines of code from being done.

Now, let’s borrow some code from my post on calculated properties in PowerShell to help us add this column and my post on seeing if a port is open using PowerShell to populate the data.

You can run $servers to see the if the new data shows up correctly (spoiler alert, it did), and then use Export-Csv to put the data into the same, or a new CSV file.

Use the -Force flag if you’re overwriting an existing CSV.

Leave a Reply