1

My script copies a directory (and all sub-directories) to a new directory named with today's date, to 10 different servers.

$ServerList = Get-Content 'C:\Users\test\Powershellskript\testservrar.txt'
ForEach ($Server in $ServerList)
{
    $source = "\\$Server\C$\Java\testIX"
    $distanation = "\\$Server\C$\Backup"
    $today = (Get-Date).ToString('YY-MM-DD')
    $location = New-Item -Path $distanation -Type Directory -Name $today
    Copy-Item $source -Destination $location -recurse
}

But I get the two errors below, how can I fix this?

Copy-Item : The symbolic link cannot be followed because its type is disabled.
At C:\Users\baa065sa\Powershell skript\Untitled1.ps1:9 char:1
Copy-Item : The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.
At C:\Users\baa065sa\Powershell skript\Untitled1.ps1:9 char:1
henrycarteruk
  • 12,708
  • 2
  • 36
  • 40
Am Ba
  • 55
  • 1
  • 2
  • 10
  • Why?! How can I explain the error? – Am Ba Sep 27 '17 at 08:17
  • Sorry the code was not formatted when I posted that and no explanation was provided, I delete my previous comment – Manu Sep 27 '17 at 08:18
  • It looks like there is a solutions here: https://stackoverflow.com/questions/229643/how-do-i-overcome-the-the-symbolic-link-cannot-be-followed-because-its-type-is – Austin T French Oct 21 '17 at 01:39

1 Answers1

2

Your first error is because remote to remote symbolic links are disabled by default.

You can check this (using an elevated command prompt) by running:

fsutil behavior query SymlinkEvaluation

Which will then return your status:

Local to local symbolic links are enabled.
Local to remote symbolic links are enabled.
Remote to local symbolic links are disabled.
Remote to remote symbolic links are disabled.

And change this behaviour using:

fsutil behavior set SymlinkEvaluation R2R:1

And query again to see the new status:

> fsutil behavior query SymlinkEvaluation

Local to local symbolic links are enabled.
Local to remote symbolic links are enabled.
Remote to local symbolic links are disabled.
Remote to remote symbolic links are enabled.

Your second error is exactly as it says:

The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters

Your destination path (\MyServerName\C$\Backup\Folder\Folder\...\file.txt) exceeds the limit in the error message.

henrycarteruk
  • 12,708
  • 2
  • 36
  • 40
  • first error: should I run fsutile behavior set SymlinkEvaluation R2R: 1 in the machine to backup? or the machine you run the script? Other error: I know there are some files they have too long names but how can backup the file without the powershell screaming! – Am Ba Sep 28 '17 at 06:38