# Using .csv columns in my script

**URL:** <https://forums.powershell.org/t/using-csv-columns-in-my-script/4323>\
**Category:** PowerShell Help\
**Created:** [June 8, 2015, 1:31am UTC](https://forums.powershell.org/t/using-csv-columns-in-my-script/4323 "2015-06-08T01:31:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![thomas-cuddy](https://avatars.discourse-cdn.com/v4/letter/t/57b2e6/32.png) [@thomas-cuddy](https://forums.powershell.org/u/thomas-cuddy)\
**Post date:** [June 8, 2015, 1:31am UTC](https://forums.powershell.org/t/using-csv-columns-in-my-script/4323/1 "2015-06-08T01:31:58Z")

</div>

Hi all,

I’m new to PowerShell and only written a couple of scripts.

I’ve tried searching out the answer but I think I’m asking the wrong thing so here goes…

I need to

```
backup-spsite http://myurl/site -path "c:backups\test.bak"

remove-spsite http://myurl/site

restore-spsite http://myurl/NEWsite -path "c:backups\test.bak"
```

My issue is I will need to run this 1200 times for different sites.

I already have an output in .csv of the old site URL and what the NEWsite URL needs to be but what I still haven’t got my head round is how I get a script that runs these 3 steps pulling the required data from the .csv file for each address.

It may be as simple as someone just telling me what I should search the web for. Any pointers to get me going would be appreciated.

I really want to get my head around it to build and learn so I’m really just looking for the bare bones to get me started.

Thanks in advance

---

<div class="post-metadata">

**Author:** ![donj](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/donj/32/137_2.png) [@donj](https://forums.powershell.org/u/donj)\
**Post date:** [June 8, 2015, 1:41am UTC](https://forums.powershell.org/t/using-csv-columns-in-my-script/4323/2 "2015-06-08T01:41:37Z")

</div>

Assuming your CSV is named MyData.csv, and assuming it has a column named New and a column named Old:

```
foreach ($line in (Import-CSV MyData.csb)) {
  $line.Old
  $line.New
}
```

You would use $line to access the current line of the file, and properties ($line.Old, for example) correspond to the column names.

Does that help?

---

<div class="post-metadata">

**Author:** ![thomas-cuddy](https://avatars.discourse-cdn.com/v4/letter/t/57b2e6/32.png) [@thomas-cuddy](https://forums.powershell.org/u/thomas-cuddy)\
**Post date:** [June 8, 2015, 7:03pm UTC](https://forums.powershell.org/t/using-csv-columns-in-my-script/4323/3 "2015-06-08T19:03:20Z")

</div>

Perfect, thats exactly what I needed. Thanks Don,

Hopefully start my month of lunches today if amazon deliver on time but that will get me going in the meantime.

Cheers.

Thomas

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:45pm UTC](https://forums.powershell.org/t/using-csv-columns-in-my-script/4323/4 "2024-05-16T20:45:11Z")

</div>


