Using .csv columns in my script


This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of Thomas Cuddy Thomas Cuddy 1 year, 4 months ago.

  • Author
  • #26094
    Profile photo of Thomas Cuddy
    Thomas Cuddy

    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

  • #26096
    Profile photo of Don Jones
    Don Jones

    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)) {

    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?

  • #26179
    Profile photo of Thomas Cuddy
    Thomas Cuddy

    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.



You must be logged in to reply to this topic.