copy-item multiple times

This topic contains 2 replies, has 2 voices, and was last updated by  Tony Antony 1 month ago.

  • Author
    Posts
  • #82136

    Tony Antony
    Participant

    I have a script below to copy a file into another folder multiple times. I have a csv file with 3 names, and it's suppose to copy the file 3 times, but it's only copying it one time. How would I make it copy more than one time?

    $csv_location = '\\arg-fs2\users\tantony\PowerShell\Outlook email signature\employees_info.csv'
    $html_files_location = '\\arg-fs2\users\tantony\PowerShell\Outlook email signature\User Outlook Signatures'
    $master_html_file = '\\arg-fs2\users\tantony\PowerShell\Outlook email signature\htmlCodeMaster.txt'
    $read_csv = Import-Csv -Path $csv_location
    
    foreach ($employees in $read_csv) {
        Remove-Item $html_files_location\* -Force        
        $txt_file_names = ($employees.Name) + ".txt"  
        Copy-Item -Path $master_html_file -Destination $html_files_location\$txt_file_names
    }
  • #82139

    Curtis Smith
    Participant

    It actually is copying 3 times, but you are deleting all of the files each time inside of the loop so the end result is only 1 file remains when it's done.

    You should move

    Remove-Item $html_files_location\* -Force

    outside of the loop

  • #82304

    Tony Antony
    Participant

    Ofcourse, simple mistake.

    It worked thanks.

You must be logged in to reply to this topic.