I have this script copying first month backup file from directory to another. This works fine but needs user intervention and not execute automatically. How i can silent this message ?


Here is the code:

$bak_path = "C:\Users\admin\Pictures\test"
$backup_dest = "C:\Users\admin\Pictures\paste"
get-childitem -path $bak_path -Filter "*" | 
    where-object { -not $_.PSIsContainer }  | 
    sort-object -Property $_.CreationTime | 
    select-object -last 1 | 
    copy-item -Destination (join-path $backup_dest )

Your problem is join-path. You need to supply a path and a child path. So by doing that you would get rid of the prompt. It's unclear why that join-path is there in the first place. It's likely that you could just leave it out.


This message comes from join-path, since join-path needs a -Path and a -ChildPath to work.

so your command should look like this join-path -path $backup_dest -childpath xy

but in my opinion, you don't need join-path at all.

why not just copy-item -Destination $backup_dest?

which paths do you want to join?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.