File name too long to sync onedrive

I have recently moved all my dropbox files to onedrive in an effort to migrate.  Unfortunately, one drive does not provide an easy way to resolve the file size errors.  You cannot see the file in internet explorer view.  You are not told how many files there are to shorten.  And you must do them one-by-one.  There has to be a better way.

Assistance is greatly appreciated.
frugalmuleAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rezsupportCommented:
Sure, here is a script that should help automate the process for you. Save it as a ps1.



function Check-IllegalCharacters ($Path, [switch]$Fix, [switch]$Verbose)
{
    Write-Host Checking files in $Path, please wait...
    #Get all files and folders under the path specified
    $items = Get-ChildItem -Path $Path -Recurse
    foreach ($item in $items)
    {
        #Check if the item is a file or a folder
        if ($item.PSIsContainer) { $type = "Folder" }
        else { $type = "File" }
       
        #Report item has been found if verbose mode is selected
        if ($Verbose) { Write-Host Found a $type called $item.FullName }
       
        #Check if item name is 128 characters or more in length
        if ($item.Name.Length -gt 127)
        {
            Write-Host $type $item.Name is 128 characters or over and will need to be truncated -ForegroundColor Red
        }
        else
        {
            #Got this from http://powershell.com/cs/blogs/tips/archive/2011/05/20/finding-multiple-regex-matches.aspx
            $illegalChars = '[&{}~#%]'
            filter Matches($illegalChars)
            {
                $item.Name | Select-String -AllMatches $illegalChars |
                Select-Object -ExpandProperty Matches
                Select-Object -ExpandProperty Values
            }
           
            #Replace illegal characters with legal characters where found
            $newFileName = $item.Name
            Matches $illegalChars | ForEach-Object {
                Write-Host $type $item.FullName has the illegal character $_.Value -ForegroundColor Red
                #These characters may be used on the file system but not SharePoint
                if ($_.Value -match "&") { $newFileName = ($newFileName -replace "&", "and") }
                if ($_.Value -match "{") { $newFileName = ($newFileName -replace "{", "(") }
                if ($_.Value -match "}") { $newFileName = ($newFileName -replace "}", ")") }
                if ($_.Value -match "~") { $newFileName = ($newFileName -replace "~", "-") }
                if ($_.Value -match "#") { $newFileName = ($newFileName -replace "#", "") }
                if ($_.Value -match "%") { $newFileName = ($newFileName -replace "%", "") }
            }
           
            #Check for start, end and double periods
            if ($newFileName.StartsWith(".")) { Write-Host $type $item.FullName starts with a period -ForegroundColor red }
            while ($newFileName.StartsWith(".")) { $newFileName = $newFileName.TrimStart(".") }
            if ($newFileName.EndsWith(".")) { Write-Host $type $item.FullName ends with a period -ForegroundColor Red }
            while ($newFileName.EndsWith("."))   { $newFileName = $newFileName.TrimEnd(".") }
            if ($newFileName.Contains("..")) { Write-Host $type $item.FullName contains double periods -ForegroundColor red }
            while ($newFileName.Contains(".."))  { $newFileName = $newFileName.Replace("..", ".") }
           
            #Fix file and folder names if found and the Fix switch is specified
            if (($newFileName -ne $item.Name) -and ($Fix))
            {
                Rename-Item $item.FullName -NewName ($newFileName)
                Write-Host $type $item.Name has been changed to $newFileName -ForegroundColor Blue
            }
        }
    }
}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
frugalmuleAuthor Commented:
where should I put it?
0
David Johnson, CD, MVPOwnerCommented:
NO POINTS:
save the following as Check-IllegalCharacters.ps1
Doesn't matter where you save it

  <#
            .AUTHORS
            RezSupport
            David Johnson (ve3ofa)

            .VERSION
            1.01

            .FILENAME
          Save as "Check-IllegalCharacters.ps1"
           
           .SYNOPSIS 
          Checks and Optionally Fixes Files with Illegal Characters
          or FilePaths > 127 Characters

           .DESCRIPTION
          The Check-IllegalCharacters.ps1 script checks the path given
           for files with illegal characters and filelenghts greater than 
           127 characters for input to Onedrive
              
           .PARAMETER Path
           Specifies the path to the Root Directory to Search

           .PARAMETER -Fix
           Will Fix files with Illegal Filenames

           .PARAMETER -Verbose
           Will Give Verbose Output 
           
           .INPUTS
           None. You cannot pipe objects to Check-IllegalCharacters.ps1.

           .OUTPUTS
           None. Check-IllegalCharacters.ps1 does not generate any output.

           .EXAMPLE
           C:\PS> .\Check-IllegalCharacters.ps1 -path c:\

           .EXAMPLE
           C:\PS> .\Check-IllegalCharacters.ps1 -path C:\Data\ -Fix

           .EXAMPLE
           C:\PS> .\Check-IllegalCharacters.ps1 -path C:\Data\ - Verbose
           #>


[CmdletBinding()]
Param(
    [Parameter(Mandatory=$True)]
        [string]$Path,
        [Parameter(Mandatory=$False)]
        [switch] $Fix
        )       
    if (test-path $path) {
    Write-Host Checking files in $Path, please wait...
    #Get all files and folders under the path specified
    $items = Get-ChildItem -Path $Path -Recurse
    foreach ($item in $items)
    {
        #Check if the item is a file or a folder
        if ($item.PSIsContainer) { $type = "Folder" }
        else { $type = "File" }
       
        #Report item has been found if verbose mode is selected
        if ($Verbose) { Write-Host Found a $type called $item.FullName }
       
        #Check if item name is 128 characters or more in length
        if ($item.Name.Length -gt 127)
        {
            Write-Host $type $item.Name is 128 characters or over and will need to be truncated -ForegroundColor Red
        }
        else
        {
            #Got this from http://powershell.com/cs/blogs/tips/archive/2011/05/20/finding-multiple-regex-matches.aspx
            $illegalChars = '[&{}~#%]'
            filter Matches($illegalChars)
            {
                $item.Name | Select-String -AllMatches $illegalChars |
                Select-Object -ExpandProperty Matches
                Select-Object -ExpandProperty Values
            }
           
            #Replace illegal characters with legal characters where found
            $newFileName = $item.Name
            Matches $illegalChars | ForEach-Object {
                Write-Host $type $item.FullName has the illegal character $_.Value -ForegroundColor Red
                #These characters may be used on the file system but not SharePoint
                if ($_.Value -match "&") { $newFileName = ($newFileName -replace "&", "and") }
                if ($_.Value -match "{") { $newFileName = ($newFileName -replace "{", "(") }
                if ($_.Value -match "}") { $newFileName = ($newFileName -replace "}", ")") }
                if ($_.Value -match "~") { $newFileName = ($newFileName -replace "~", "-") }
                if ($_.Value -match "#") { $newFileName = ($newFileName -replace "#", "") }
                if ($_.Value -match "%") { $newFileName = ($newFileName -replace "%", "") }
            }
           
            #Check for start, end and double periods
            if ($newFileName.StartsWith(".")) { Write-Host $type $item.FullName starts with a period -ForegroundColor red }
            while ($newFileName.StartsWith(".")) { $newFileName = $newFileName.TrimStart(".") }
            if ($newFileName.EndsWith(".")) { Write-Host $type $item.FullName ends with a period -ForegroundColor Red }
            while ($newFileName.EndsWith("."))   { $newFileName = $newFileName.TrimEnd(".") }
            if ($newFileName.Contains("..")) { Write-Host $type $item.FullName contains double periods -ForegroundColor red }
            while ($newFileName.Contains(".."))  { $newFileName = $newFileName.Replace("..", ".") }
           
            #Fix file and folder names if found and the Fix switch is specified
            if (($newFileName -ne $item.Name) -and ($Fix))
            {
                Rename-Item $item.FullName -NewName ($newFileName)
                Write-Host $type $item.Name has been changed to $newFileName -ForegroundColor Blue
            }
        }
    }
 }
 else {
 Write-host("Path " + $path + " Does Not Exist")
 }

Open in new window

0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

frugalmuleAuthor Commented:
Thanks very much.  Still having some issues http://screencast.com/t/BHGDV60yhQ
0
David Johnson, CD, MVPOwnerCommented:
you have to execute the file using powershell
0
frugalmuleAuthor Commented:
I apologize. Can you tell me how I would execute it?
0
rezsupportCommented:
Open PS as an admin (right click and click run as administrator) browse to the location of the ps1 file you just created and type the first few letters of the file name and hit tab. Then hit enter to execute.
0
frugalmuleAuthor Commented:
Thanks for the suggestion.  I did run as admin but got this error.

http://screencast.com/t/sGVHVpqJikg
0
David Johnson, CD, MVPOwnerCommented:
Set-ExecutionPolicy RemoteSigned
accept the prompt to change the execution policy from restricted
now run the script
0
frugalmuleAuthor Commented:
can I restrict the policy any further where it will still allow the script to run for me the user only
0
frugalmuleAuthor Commented:
I did run the Set-ExcecutionPolicy RemoteSigned successfully.  After that, I ran into some trouble as shown here http://screencast.com/t/KhywtwCdQC.  I saved the file as a ps1 file, right clicked and said run in powershell.  Not much luck.
0
David Johnson, CD, MVPOwnerCommented:
it is asking for a starting directory (path)
0
frugalmuleAuthor Commented:
I'm confused.  If you could post the command that I should put in and where, that would be great.  Do right click the file to run it?  If it wants the path to OneDrive, it is actually C:\Users\Ted\SkyDrive
0
frugalmuleAuthor Commented:
Thanks for the help.  I appreciate it very much.  These are the steps I took but still get the same error.

http://screencast.com/t/W8z5E6yGD
0
David Johnson, CD, MVPOwnerCommented:
Added some error checking
http://screencast.com/t/6D4t7j3sqL
  <#
            .AUTHORS
            RezSupport
            David Johnson (ve3ofa)

            .VERSION
            1.01
            1.02 Added Error Checking for any File Exception
            .FILENAME
          Save as "Check-IllegalCharacters.ps1"
           
           .SYNOPSIS 
          Checks and Optionally Fixes Files with Illegal Characters
          or FilePaths > 127 Characters

           .DESCRIPTION
          The Check-IllegalCharacters.ps1 script checks the path given
           for files with illegal characters and filelenghts greater than 
           127 characters for input to Onedrive
              
           .PARAMETER Path
           Specifies the path to the Root Directory to Search

           .PARAMETER -Fix
           Will Fix files with Illegal Filenames

           .PARAMETER -Verbose
           Will Give Verbose Output 
           
           .INPUTS
           None. You cannot pipe objects to Check-IllegalCharacters.ps1.

           .OUTPUTS
           None. Check-IllegalCharacters.ps1 does not generate any output.

           .EXAMPLE
           C:\PS> .\Check-IllegalCharacters.ps1 -path c:\

           .EXAMPLE
           C:\PS> .\Check-IllegalCharacters.ps1 -path C:\Data\ -Fix

           .EXAMPLE
           C:\PS> .\Check-IllegalCharacters.ps1 -path C:\Data\ - Verbose
           #>


[CmdletBinding()]
Param(
    [Parameter(Mandatory=$True)]
        [string]$Path,
        [Parameter(Mandatory=$False)]
        [switch] $Fix
        )       
    if (test-path $path) {
    Write-Host Checking files in $Path, please wait...
    #Get all files and folders under the path specified
    
    $items = Get-ChildItem –Force –Recurse  -ErrorAction SilentlyContinue –ErrorVariable AccessDenied -Path $Path
    $AccessDenied | ForEach-Object {
        $_.TargetObject
        $_.Exception
    }
    
    foreach ($item in $items)
    {
        #Check if the item is a file or a folder
        if ($item.PSIsContainer) { $type = "Folder" }
        else { $type = "File" }
       
        #Report item has been found if verbose mode is selected
        if ($Verbose) { Write-Host Found a $type called $item.FullName }
       
        #Check if item name is 128 characters or more in length
        if ($item.Name.Length -gt 127)
        {
            Write-Host $type $item.Name is 128 characters or over and will need to be truncated -ForegroundColor Red
        }
        else
        {
            #Got this from http://powershell.com/cs/blogs/tips/archive/2011/05/20/finding-multiple-regex-matches.aspx
            $illegalChars = '[&{}~#%]'
            filter Matches($illegalChars)
            {
                $item.Name | Select-String -AllMatches $illegalChars |
                Select-Object -ExpandProperty Matches
                Select-Object -ExpandProperty Values
            }
           
            #Replace illegal characters with legal characters where found
            $newFileName = $item.Name
            Matches $illegalChars | ForEach-Object {
                Write-Host $type $item.FullName has the illegal character $_.Value -ForegroundColor Red
                #These characters may be used on the file system but not SharePoint
                if ($_.Value -match "&") { $newFileName = ($newFileName -replace "&", "and") }
                if ($_.Value -match "{") { $newFileName = ($newFileName -replace "{", "(") }
                if ($_.Value -match "}") { $newFileName = ($newFileName -replace "}", ")") }
                if ($_.Value -match "~") { $newFileName = ($newFileName -replace "~", "-") }
                if ($_.Value -match "#") { $newFileName = ($newFileName -replace "#", "") }
                if ($_.Value -match "%") { $newFileName = ($newFileName -replace "%", "") }
            }
           
            #Check for start, end and double periods
            if ($newFileName.StartsWith(".")) { Write-Host $type $item.FullName starts with a period -ForegroundColor red }
            while ($newFileName.StartsWith(".")) { $newFileName = $newFileName.TrimStart(".") }
            if ($newFileName.EndsWith(".")) { Write-Host $type $item.FullName ends with a period -ForegroundColor Red }
            while ($newFileName.EndsWith("."))   { $newFileName = $newFileName.TrimEnd(".") }
            if ($newFileName.Contains("..")) { Write-Host $type $item.FullName contains double periods -ForegroundColor red }
            while ($newFileName.Contains(".."))  { $newFileName = $newFileName.Replace("..", ".") }
           
            #Fix file and folder names if found and the Fix switch is specified
            if (($newFileName -ne $item.Name) -and ($Fix))
            {
                Rename-Item $item.FullName -NewName ($newFileName)
                Write-Host $type $item.Name has been changed to $newFileName -ForegroundColor Blue
            }
        }
    }
 }
 else {
 Write-host("Path " + $path + " Does Not Exist")
 }
# SIG # Begin signature block
# MIINGAYJKoZIhvcNAQcCoIINCTCCDQUCAQExCzAJBgUrDgMCGgUAMGkGCisGAQQB
# gjcCAQSgWzBZMDQGCisGAQQBgjcCAR4wJgIDAQAABBAfzDtgWUsITrck0sYpfvNR
# AgEAAgEAAgEAAgEAAgEAMCEwCQYFKw4DAhoFAAQUP4Chs1Fb2XxmcAyA6UEi8rvt
# /xGgggpaMIIFIjCCBAqgAwIBAgIQAupQIxjzGlMFoE+9rHncOTANBgkqhkiG9w0B
# AQsFADByMQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYD
# VQQLExB3d3cuZGlnaWNlcnQuY29tMTEwLwYDVQQDEyhEaWdpQ2VydCBTSEEyIEFz
# c3VyZWQgSUQgQ29kZSBTaWduaW5nIENBMB4XDTE0MDcxNzAwMDAwMFoXDTE1MDcy
# MjEyMDAwMFowaTELMAkGA1UEBhMCQ0ExCzAJBgNVBAgTAk9OMREwDwYDVQQHEwhI
# YW1pbHRvbjEcMBoGA1UEChMTRGF2aWQgV2F5bmUgSm9obnNvbjEcMBoGA1UEAxMT
# RGF2aWQgV2F5bmUgSm9obnNvbjCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC
# ggEBAM3+T+61MoGxUHnoK0b2GgO17e0sW8ugwAH966Z1JIzQvXFa707SZvTJgmra
# ZsCn9fU+i9KhC0nUpA4hAv/b1MCeqGq1O0f3ffiwsxhTG3Z4J8mEl5eSdcRgeb+1
# jaKI3oHkbX+zxqOLSaRSQPn3XygMAfrcD/QI4vsx8o2lTUsPJEy2c0z57e1VzWlq
# KHqo18lVxDq/YF+fKCAJL57zjXSBPPmb/sNj8VgoxXS6EUAC5c3tb+CJfNP2U9vV
# oy5YeUP9bNwq2aXkW0+xZIipbJonZwN+bIsbgCC5eb2aqapBgJrgds8cw8WKiZvy
# Zx2qT7hy9HT+LUOI0l0K0w31dF8CAwE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bs9EWp7NO+aFG
# mhxtwHAWf+WAMA0GCSqGSIb3DQEBAQUABIIBALe0kGB/GPbwfsvuUToffqfkIazu
# 1bKzXnknhWlYGrmrubhRYAWbmoIh6xnQP16aNYVg/dMk5RuWwg2+jV9w4mGf3GGz
# ztjHKH9A8/DzWjlAonSAXZ6EwmFGROf68BbgtYdDcdp0kAVHu2rYihS+Ia2os9r1
# MJ9m/ui/l/pUwXDQbhZirDh1wWk3cVOjZHqfS3C0w2ORaYRTiu0vawD/2u3jlt7N
# KlbyYwzUEB0VVqjIfGMdRTitm/PELYsfGDaI/nx5eUYv5jTqmFBqNFzeeBCHJFuW
# r5yS96GymJwXh3kVL0iDnLCQNiFzaBMDE/J5lp4OBEFj7++tVjnTFi4ZWrc=
# SIG # End signature block

Open in new window

0
frugalmuleAuthor Commented:
Thanks for the help.  I appreciate it very much.  These are the steps I took but still get the same error.

http://screencast.com/t/mqK3HjAn
0
David Johnson, CD, MVPOwnerCommented:
Changed the write-host to write-output this way you can pipe the output to a file i.e.
from a powershell command prompt (start powershell)

.\Check-IllegalCharacters.ps1  -path c:\whatever  > output.txt
http://www.screencast.com/t/Ci9DLY78R4
  <#
            .AUTHORS
            RezSupport
            David Johnson (ve3ofa)

            .VERSION
            1.01
            1.02 Added Error Checking for any File Exception
            1.03 Replaced Write-Output with write-output and added proper
                 atribution http://get-spscripts.com/2011_11_01_archive.html
            .FILENAME
          Save as "Check-IllegalCharacters.ps1"
           
           .SYNOPSIS 
          Checks and Optionally Fixes Files with Illegal Characters
          or FilePaths > 127 Characters

           .DESCRIPTION
          The Check-IllegalCharacters.ps1 script checks the path given
           for files with illegal characters and filelenghts greater than 
           127 characters for input to Onedrive
              
           .PARAMETER Path
           Specifies the path to the Root Directory to Search

           .PARAMETER -Fix
           Will Fix files with Illegal Filenames

           .PARAMETER -Verbose
           Will Give Verbose Output 
           
           .INPUTS
           None. You cannot pipe objects to Check-IllegalCharacters.ps1.

           .OUTPUTS
           None. Check-IllegalCharacters.ps1 does not generate any output.

           .EXAMPLE
           C:\PS> .\Check-IllegalCharacters.ps1 -path c:\

           .EXAMPLE
           C:\PS> .\Check-IllegalCharacters.ps1 -path C:\Data\ -Fix

           .EXAMPLE
           C:\PS> .\Check-IllegalCharacters.ps1 -path C:\Data\ - Verbose
           #>


[CmdletBinding()]
Param(
    [Parameter(Mandatory=$True)]
        [string]$Path,
        [Parameter(Mandatory=$False)]
        [switch] $Fix
        )       
    if (test-path $path) {
    $output = "Checking files in "+$path+" ...please wait..."
    Write-Output $output
    #Get all files and folders under the path specified
    
    $items = Get-ChildItem –Force –Recurse  -ErrorAction SilentlyContinue –ErrorVariable AccessDenied -Path $Path
    $AccessDenied | ForEach-Object {
        $_.TargetObject
        $_.Exception
    }
    
    foreach ($item in $items){
        #Check if the item is a file or a folder
        if ($item.PSIsContainer) { $type = "Folder" }
        else { $type = "File" }
       
        #Report item has been found if verbose mode is selected
        if ($Verbose) { 
            Write-Verbose (Found a $type called $item.FullName) 
        }
       
        #Check if item name is 128 characters or more in length
        if ($item.Name.Length -gt 127)
        {
        $output =$type +" " + $item.Name + " is 128 characters or over and will need to be truncated "
            Write-Output $output

        }
        else
        {
            #Got this from http://powershell.com/cs/blogs/tips/archive/2011/05/20/finding-multiple-regex-matches.aspx
            $illegalChars = '[&{}~#%]'
            filter Matches($illegalChars)
            {
                $item.Name | Select-String -AllMatches $illegalChars |
                Select-Object -ExpandProperty Matches
                Select-Object -ExpandProperty Values
            }
           
            #Replace illegal characters with legal characters where found
            $newFileName = $item.Name
            Matches $illegalChars | ForEach-Object {
                $output = $type+" "+$item.FullName+ " has the illegal character "+ $_.Value
                Write-Output $output
                #These characters may be used on the file system but not SharePoint
                if ($_.Value -match "&") { $newFileName = ($newFileName -replace "&", "and") }
                if ($_.Value -match "{") { $newFileName = ($newFileName -replace "{", "(") }
                if ($_.Value -match "}") { $newFileName = ($newFileName -replace "}", ")") }
                if ($_.Value -match "~") { $newFileName = ($newFileName -replace "~", "-") }
                if ($_.Value -match "#") { $newFileName = ($newFileName -replace "#", "") }
                if ($_.Value -match "%") { $newFileName = ($newFileName -replace "%", "") }
            }
           
            #Check for start, end and double periods
            if ($newFileName.StartsWith(".")) 
                { 
                $output = $type+" "+ $item.FullName+" starts with a period"
                Write-Output $output
                }
            while ($newFileName.StartsWith(".")) 
                { 
                $newFileName = $newFileName.TrimStart(".") 
                }
            if ($newFileName.EndsWith(".")) 
                { 
                $output = $type+" "+$item.FullName+" ends with a period"
                Write-Output  $output
                }
            while ($newFileName.EndsWith("."))   { 
                $newFileName = $newFileName.TrimEnd(".") 
                }
            if ($newFileName.Contains("..")) 
                { 
                $output = $type+" "+$item.FullName+" contains double periods"
                Write-Output $output
                }
            while ($newFileName.Contains(".."))  
                { 
                $newFileName = $newFileName.Replace("..", ".") 
                }
           
            #Fix file and folder names if found and the Fix switch is specified
            if (($newFileName -ne $item.Name) -and ($Fix)){
                Rename-Item $item.FullName -NewName ($newFileName)
                $output = $type+" "+$item.Name+" has been changed to "+$newFileName
                Write-Output $output
                }
            }
        }
    }
 
 
 else {
 Write-Output("Path " + $path + " Does Not Exist")
 }
# SIG # Begin signature block
# MIINGAYJKoZIhvcNAQcCoIINCTCCDQUCAQExCzAJBgUrDgMCGgUAMGkGCisGAQQB
# gjcCAQSgWzBZMDQGCisGAQQBgjcCAR4wJgIDAQAABBAfzDtgWUsITrck0sYpfvNR
# AgEAAgEAAgEAAgEAAgEAMCEwCQYFKw4DAhoFAAQUP4Chs1Fb2XxmcAyA6UEi8rvt
# /xGgggpaMIIFIjCCBAqgAwIBAgIQAupQIxjzGlMFoE+9rHncOTANBgkqhkiG9w0B
# AQsFADByMQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYD
# VQQLExB3d3cuZGlnaWNlcnQuY29tMTEwLwYDVQQDEyhEaWdpQ2VydCBTSEEyIEFz
# c3VyZWQgSUQgQ29kZSBTaWduaW5nIENBMB4XDTE0MDcxNzAwMDAwMFoXD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HJyqhKSgaOnEoAjwukaPAJRHinBRHoXpoaK+bp1wgXNlxsQyP
# u6j4xRJon89Ay0BEpRPw5mQMJQhCMrI2iiQC/i9yfhzXSUWW6Fkd6fp0ZGuy62ZD
# 2rOwjNXpDd32ASDOmTFjPQgaGLOBm0/GkxAG/AeB+ova+YJJ92JuoVP6EpQYhS6S
# kepobEQysmah5xikmmRR7zGCAigwggIkAgEBMIGGMHIxCzAJBgNVBAYTAlVTMRUw
# EwYDVQQKEwxEaWdpQ2VydCBJbmMxGTAXBgNVBAsTEHd3dy5kaWdpY2VydC5jb20x
# MTAvBgNVBAMTKERpZ2lDZXJ0IFNIQTIgQXNzdXJlZCBJRCBDb2RlIFNpZ25pbmcg
# Q0ECEALqUCMY8xpTBaBPvax53DkwCQYFKw4DAhoFAKB4MBgGCisGAQQBgjcCAQwx
# CjAIoAKAAKECgAAwGQYJKoZIhvcNAQkDMQwGCisGAQQBgjcCAQQwHAYKKwYBBAGC
# NwIBCzEOMAwGCisGAQQBgjcCARUwIwYJKoZIhvcNAQkEMRYEFGgbs9EWp7NO+aFG
# mhxtwHAWf+WAMA0GCSqGSIb3DQEBAQUABIIBALe0kGB/GPbwfsvuUToffqfkIazu
# 1bKzXnknhWlYGrmrubhRYAWbmoIh6xnQP16aNYVg/dMk5RuWwg2+jV9w4mGf3GGz
# ztjHKH9A8/DzWjlAonSAXZ6EwmFGROf68BbgtYdDcdp0kAVHu2rYihS+Ia2os9r1
# MJ9m/ui/l/pUwXDQbhZirDh1wWk3cVOjZHqfS3C0w2ORaYRTiu0vawD/2u3jlt7N
# KlbyYwzUEB0VVqjIfGMdRTitm/PELYsfGDaI/nx5eUYv5jTqmFBqNFzeeBCHJFuW
# r5yS96GymJwXh3kVL0iDnLCQNiFzaBMDE/J5lp4OBEFj7++tVjnTFi4ZWrc=
# SIG # End signature block
 

Open in new window

0
frugalmuleAuthor Commented:
I see now.  I though you were working on something to fix the illegal characters so that the sync would work.
0
David Johnson, CD, MVPOwnerCommented:
from a powershell command prompt or the powershell ISE
check-illegalcharacters.ps1 -path c:\abc -fix
type help check-illegalcharacters.ps1 to see the syntax
0
frugalmuleAuthor Commented:
I tried the latest code again with the -fix switch.  Still no luck getting it to work.  Here is the syntax I used as well as the error.Capture
0
David Johnson, CD, MVPOwnerCommented:
that means that check-illegalcharacters.ps1 is not in that directory
c:\test\check-illegalcharacters.ps1 -path c:\users\ted\skydrive -fix
0
frugalmuleAuthor Commented:
Still no luck using that path either http://screencast.com/t/n0D66ZCypydZ.
0
David Johnson, CD, MVPOwnerCommented:
what if you type "check" and then press the tab key
the c:\test\ is the location that you saved the .ps1 file.
0
frugalmuleAuthor Commented:
yes to the second line

here is the result of check http://screencast.com/t/tD4rUqeCNK31
0
David Johnson, CD, MVPOwnerCommented:
right click on the powershell ise or select powershell ise (run as administrator) once it comes up
set-executionpolicy remotesigned  (accept the prompt)
0
frugalmuleAuthor Commented:
still no luck for me
0
frugalmuleAuthor Commented:
It seems we are having difficulty connecting.
0
frugalmuleAuthor Commented:
now we can't even see the sync status anymore ??
0
frugalmuleAuthor Commented:
We got past this and are no longer receiving the long file name error.  Now we still can't get the upload to finish though Here is the new question >> http://www.experts-exchange.com/Networking/Cloud_Computing/Q_28654182.html
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Office

From novice to tech pro — start learning today.