powershell script to copy files based on an excel spreadsheet RRS feed

  • Question

  • All,

    Looking for some help to acheive the following.

    1) i have a reference file pst.csv with 2 columns

    file path       user

    \\XXX\X.pst       XXX\XXXXXX


    2) i need to parse the csv file and copy the files in column A to a destination location.

    3) then re-acl the file based on the user column

    I have tried get-content of the csv file and then parse it but am having a nightmare any pointers would be most appreicated.

    Cheers all


    Tuesday, May 18, 2010 8:32 PM


All replies

  • import-csv pst.csv | foreach {copy-item $_.filepath "c:\share"}

    filepath is the name of your column header in the CSV.

    There is some information on modifying file ACLs in this thread:



    • Proposed as answer by LikeToCode Sunday, July 18, 2010 2:14 AM
    • Marked as answer by IamMred Tuesday, August 17, 2010 4:11 PM
    Saturday, July 17, 2010 3:13 PM
  • I am looking for a similar solution if you don't mind me jumping in on this thread

    I would like to be able to get variables from a .csv in multiple columns for creating directories, copying and the likes

    EG: I haved a scipt which will use a .csv to lookup a varible to copy out to all server DFS paths

    code: gc "Q:\\DistributeScripts\DFSpaths.csv" | ForEach { Copy C:Temp\PrinterBack.cmd -Dest $_\SUPPORT\Scripts -recurse }


    What would like to do is pull 2,3 or 4 variables from the one .csv which would be in columns


    Eg: I'm trying to create a Directory structure on 100+ servers from a 2 columns in the .csv


    gc c:\Temp\SchoolVariables.csv -header ("SiteCode","DFS") | ForEach { [IO.Directory]::CreateDirectory + $_.DFS + " " + $_.Sitecode ("First Column:" + $_.SiteCode + " Second Column:" + $_.DFS) }


    I'm no scriptor by any means, just mash things together & the above certainly doesn't work


    Any Ideas?


    Tuesday, July 27, 2010 2:25 AM
  • I think using Import-Csv will make the data easier to work with than using Get-Content. Try something like this:

    import-csv ./test.csv | foreach { New-Item -ItemType directory -Path $_.DFS -name $_.sitecode}
    • Marked as answer by IamMred Tuesday, August 17, 2010 4:11 PM
    Tuesday, July 27, 2010 3:49 AM