I am trying to run a simple powershell script to copy all changed files to another server as it is not in a domain so using DFS is not an option. The script is as follows,


$Source = gci “Path” -Recurse | Where-Object{$.Name -notlike “*.log”}
$Dest = “\IP\e$”
$Username = “USERNAME”
$Password = get-content “PATH” | convertto-securestring
$mycreds = New-Object System.Management.Automation.PSCredential($Username, $Password)
$Logfile = "PATH\Filesync

#Delete log file if larger than 1GB
Get-ChildItem “PATH” | Where-Object{$_.Length -gt 1gb} | Remove-Item

#Copy data to Server
New-PSDrive -Name x -PSProvider FileSystem -Root $Dest -Credential $mycreds
Robocopy $Source $Dest /MIR /log:$Logfile
Remove-PSDrive -Name X



My issue is that i get the below error. From what i can see this is a name length issue with powershell. I cannot change the file names as they are used by the application. Is there another way to get round this?

Hello Leon,

Looks like the error message didn’t come through. Please upload the error message as well for review. You can use /XF selection option to exclude the log files. Example below.

Robocopy.exe $Source $Destination /XF *.log