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
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?