Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

CSV Array Script Issues

$
0
0

Hi All,

Just posting because I'm having a little trouble with a script I'm working on that will copy some of our user's Outlook Files folder to a remote server.  First, I'm storing their computer names and usernames in a csv file that has Computer and User as the headers.  Will post that below along with the scripts.  The script below works but the issue I am having is when calling the arrays during robocopy it is also trying to copy directories that don't actually exist.  Each line in the csv should ideally be grouped together and not used with any other lines, for example it is trying to copy \\computer1\c$\users\user2\documents\outlook files and \\computer2\c$\users\user1\documents\outlook files\ when they don't exist.  I need to make it so each line stays together and then moves to the next, so when working correctly it should only robocopy \\computer1\c$\user1\documents\outlook files\ and then move on to \\computer2\c$\users2\documents\outlook files\ and so on.  I've just started working with powershell over the last few weeks and this has me stumped hopefully someone can figure out what my problem is and help me improve this script :)

 

CSV:

Computer,User
computer1,user1
computer2,user2

Script:

$csv=import-csv c:\archivebackup\archive.csv
$computers  = $csv | % { $_.computer }
$users  = $csv | % { $_."user" }
    Foreach ($computer in $computers) {
        pskill \\$computer Outlook.exe
}
    Foreach ($user in $users) {
        New-Item -Force -ItemType directory -Path  \\maserver\"Mail Archives Vol I"\$user\
}
        Foreach ($user in $users) {
            Foreach ($computer in $computers) {
                robocopy "\\$computer\c$\users\$user\documents\outlook files" "\\remoteserver\Mail Archives Vol I\$user" /copyall /r:3
    }
}

 


Viewing all articles
Browse latest Browse all 6937

Trending Articles