Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

How to loop through 2 columns in foreach loop

$
0
0

I am trying to copy multiple files from one location to another. I have the source path and destination path in SQL table. Is there a way in powershell to loop through each of the row from the result set of SQL table and use "Copy-item" for each row. 

Below is the what I have so far, I want to use foreachloop and go through each row and copy file from source to destination. 

$select_query = "select source_path, destination_path from table_commands order by id" 
$copy_commands = Invoke-Sqlcmd -ServerInstance "server_name" -Database "database_name" -Query $select_query | select source_path, destination_path

Copy-Item $source_path -Destination $destination_path


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>