Jump to content

Powershell experts need help


libraguy863

Recommended Posts

PS experts need help copying files from source to dest 

Src

filename_date1.csv 

filename_date2.csv 

filename_date3.csv 

Dest 

filename_date1.csv 

 

Here i want to copy the difference meaning the last 2 files only not the first ..thanks in advance

filename_date2.csv 

filename_date3.csv 

Link to comment
Share on other sites

3 hours ago, libraguy863 said:

PS experts need help copying files from source to dest 

Src

filename_date1.csv 

filename_date2.csv 

filename_date3.csv 

Dest 

filename_date1.csv 

 

Here i want to copy the difference meaning the last 2 files only not the first ..thanks in advance

filename_date2.csv 

filename_date3.csv 

I think you can try this…

Check the flags..also in case…

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/copy-item?view=powershell-7.1

Link to comment
Share on other sites

1 hour ago, dasari4kntr said:

thanks bhai appreciate the links.. the copy process is working as expected i had it working but they is a  condition to pick newer files if they get sent like yesterday and todays files are sent today .. both should be picked . based on the date im picking current but as of today i got 2 files it picked todays and not yesterdays 

that condition i want to know how.. 

Link to comment
Share on other sites

should work try this

Copy-Item \\server\Sites\xyz.com\App\scripts\xyz.txt \\server\destpath\abc\ -force
Copy-Item \\server\Sites\xyz.com\App\scripts\xyz.txt \\server\destpath\abc\ -force
Copy-Item \\server\Sites\xyz.com\App\scripts\xyz.txt \\server\destpath\abc\ -force

 

Link to comment
Share on other sites

30 minutes ago, libraguy863 said:

thanks bhai appreciate the links.. the copy process is working as expected i had it working but they is a  condition to pick newer files if they get sent like yesterday and todays files are sent today .. both should be picked . based on the date im picking current but as of today i got 2 files it picked todays and not yesterdays 

that condition i want to know how.. 

i cant recreate this scenario in my laptop..because i am using mac...just play around it...

as per my understanding...you might need to do these steps (if i am correct)...

 

1. first get the files which created today (or yesterday by tweeking th below...)

(Get-ChildItem -File | Where-Object {$_.CreationTime -gt (Get-Date).Date} | Measure-Object).Count 

 

2. do some google about "data piping". which passes the data from one cmdlet to another cmdlet...

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_pipelines?view=powershell-7.1

 

3. in the "Copy-Item" cmdlet...you can use include and exclude...
 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...