This topic contains 1 reply, has 2 voices, and was last updated by

3 weeks, 3 days ago.

  • Author
  • #173161

    Topics: 5
    Replies: 6
    Points: 26
    Rank: Member


    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_$todays_date.log"
    #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?

  • #173185

    Topics: 0
    Replies: 100
    Points: 363
    Helping Hand
    Rank: Contributor

    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

You must be logged in to reply to this topic.