copy only latest backup

i am having some windows backup folder and want to put it on some samba share folder to create a backups, problem is that in windows it creates every day backups, and i want only the latest. Files are named like:,, etc.
where is mistake? This copy all content, not only the newest one, and not only Backkup*.zip files, i put some txt and that copy also

$backuppath = "D:Backups" get-childitem -path $backuppath

get-childitem -path $backuppath -Filter “Backkup*.zip” |

where-object { -not $_.PSIsContainer } |

sort-object -Property $_.CreationTime |

select-object -last 1 | pscp -pw mypass -r $backuppath user@


In your last code line you’re using $backuppath. I think it should be $_.FullName instead. :wink: … and I think you should wrap this last command in a Foreach-Object scriptblock.

but i want to use whole folder cant understand what you mean

I understood you only wanted the the latest file?

latest file in that folder, yes.

[quote quote=290968]latest file in that folder, yes.

OK, and what does “pscp” do?

pscp for transfering files. Understand what you mean, if i want to catch a file to copy, then to work with files, not to use folder.
Can you help with that last part

can you help with that last part.

pscp is just used for transfering files

I think the mistake in your script is although you have selected the latest backup file you are passing the folder path only and not the selected file path to pscp.

" pscp -pw mypass -r $backuppath user@"

$backuppath still has D:Backups. So pscp is copying the all the contents from this folder(including .txt files or others as you have said) and that too recursively because you have -r argument as well (I think this is not required.)

this should work: pscp -pw mypass $_.FullName user@