[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 34
  • Last Modified:

How will Powershell handle files that have paths too long for a destination folder on an external drive

Hello Powershell Experts,

I was waiting for a friend at his office to get a ride home.  Before we left, he said he had to copy some files off a server and onto an external hard drive.  He opened Windows Explorer and proceeded to copy his files from the server and paste them on the external drive into a folder which he created named “Copy 12-5-17”.  A few minutes later, he received a message stating that some of the files paths would be too long for the destination.  He was given an option to skip the file or cancel.  He put a checkmark in the  “do this for all files” box and clicked on the skip button and we took off.  On the way home I learned that he did this manual process every night before heading out.  Since I’m hitting this friend up for a ride home each night for a couple of weeks, I thought I would repay his kindness by trying to automate his manual process.  The server he is a Windows Server 2012 Essentials box.  The external hard drive is connected via USB and has a folder with a share name of BackupCopies on it.  I want to use Powershell to automate this manual copy process.  Here is what I have:

$Date = Get-Date -Format MM-dd-yyyy
$BackupDirectory = "\\FileServer1\BackupCopies\Copy $Date"

if (-not(Test-Path $BackupDirectory))
    {
     New-Item -ItemType Directory -Path $BackupDirectory
     Copy-Item -Path D:\Work -Destination $BackupDirectory -Recurse -Force -ErrorAction SilentlyContinue
     Copy-Item -Path D:\Common -Destination $BackupDirectory -Recurse -Force -ErrorAction SilentlyContinue
     Copy-Item -Path D:\UserShares -Destination $BackupDirectory -Recurse -Force -ErrorAction SilentlyContinue
    }
else
    {
        Break
    }


Here are my questions:
1.       What will happen to the files that triggered the “file path too long” messages (where he just hits skip) when the copy via Powershell comes to them?  The script code has the –force and –erroraction silentlycontinue switches.  Will Powershell just skip over the files?
0
ndalmolin_13
Asked:
ndalmolin_13
  • 3
1 Solution
 
Zaheer IqbalTechnical Assurance & ImplementationCommented:
I would use Robocopy to get around long file paths.
0
 
Zaheer IqbalTechnical Assurance & ImplementationCommented:
0
 
sirbountyCommented:
I second the robocopy route - a one liner that you can easily setup in scheduled tasks.  Very simple.
1
 
ndalmolin_13Author Commented:
Robocopy did the trick.  Thanks
1
 
Zaheer IqbalTechnical Assurance & ImplementationCommented:
Excellent ;)
0

Join & Write a Comment

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now