0

I am looking for some help with a PowerShell Copy. I have done two day of online searching and still cannot figure it out. I am trying to copy files from one server to another.

Server A save .jpg files in a directory for its use.

example - 1111.111

Server B need the files with .jpg on them so iis can read them.

1111.111.jpg

when create the copy I does not read the 1111.111 and 1111.111.jpg as the same file and copies it again.

$Source = "Server A" 
$Destination = "Server B"

$ExcludeItems = @()
if (Test-Path "$Destination")
{
    $ExcludeItems += "*.jpg" 
}

Copy-Item "$Source\*" -Destination "$Destination" -Exclude $ExcludeItems -Recurse -Force
 
Get-ChildItem -Exclude "*.jpg", "*.ps1", "*.xls" | Where-Object{!$_.PsIsContainer} | Rename-Item -NewName {$_.name +".jpg"}

Remove-Item $Destination\'Animal'
Remove-Item $Destination\'Employee'
Remove-Item $Destination\'*sealed*'
Remove-Item $Destination\'*seled*'
  • Does this answer your question? [Using Get-ChildItem -Exclude or -Include returns nothing](https://stackoverflow.com/questions/38269209/using-get-childitem-exclude-or-include-returns-nothing) – zett42 Mar 23 '21 at 18:20
  • How do I incorporate it with the script above? I have tried it but I think I am missing something. – Jsnow1350 Mar 24 '21 at 17:40
  • You need to specify a wildcard path when using either `-Include` or `-Exclude`, e. g. `Get-ChildItem * -Exclude ...` – zett42 Mar 24 '21 at 17:57
  • The issue I am having is with the copy not the rename. I need to run this script every x hours. When trying to copy from Server A to Server B it does not recognize the Server A files without .jpg and the Server B files with .jpg are the same file. then it will copy all the files again. There are about 140K files in that directory and I don't want to keep copying the files. – Jsnow1350 Mar 24 '21 at 18:04

0 Answers0