Author Posts

October 14, 2017 at 4:31 pm

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

October 14, 2017 at 5:58 pm

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

October 17, 2017 at 12:51 pm

Ofcourse, simple mistake.

It worked thanks.