"A device attached to the system is not functioning " error when using robocopy to move folder in sharepoint

2

We are using Sharepoint 2010. There is a requirement to archive folders/Subfolders from a given folder to Archive folder which is part of document library. So we used Robocopy from powershell environment. But we're getting error "A device attached to the system is not functioning". ERROR 31 (0x0000001F) Changing File Attributes

Can any one help me what I have to do fix the above error.

Here is my code

    $sourceDir = "\\labserver\sites\XXX\YYY Accounts Documents"
    $targetDir = "\\labserver\sites\XXXX\Archived YYY Accounts Documents"

    $FilePath = "C:\InactiveAccount_SharepointFolder.xlsx"
    $sourceDir1= "\\labserver\sites\xxx\yyy Accounts Documents" 

$SheetName = "Sheet1"

# Create an Object Excel.Application using Com interface
$objExcel = New-Object -ComObject Excel.Application

# Disable the 'visible' property so the document won't open in excel
$objExcel.Visible = $false

# Open the Excel file and save it in $WorkBook
$WorkBook = $objExcel.Workbooks.Open($FilePath)


$strSheetName = "sheet1"
# Load the WorkSheet 'BuildSpecs'
 if ($strSheetName -eq "")
    {
    $worksheet = $WorkBook.sheets.item(1)
    }
    else
    {
    $worksheet = $WorkBook.sheets.item($strSheetName)
    }
try {
     $intRowMax = ($worksheet.UsedRange.Rows).count

    for($intRow = 2 ; $intRow -le $intRowMax ; $intRow++)
    {

        $isFodlerExists  = $worksheet.cells.item($intRow,3).value2
        if($isFodlerExists -match "Yes")
        {


            $accountName  = $worksheet.cells.item($intRow,1).value2
            #[system.io.directory]::CreateDirectory($tempSource + $accountName)
            #write-host $accountName
            $sFolder =  $sourceDir + "\" + $accountName
            $sFolder1 =  $sourceDir1 + "\" + $accountName
            write-host $sFolder
            $tFolder = $targetDir 
            Add-Content -Path $ErrorLog  -Value $sFolder
             if((Test-path -Path $sFolder1) -eq $TRUE)
             {
                try {

                    #Copy-Item -Path $sFolder   -Destination $tFolder -Recurse -force 
                   robocopy $sFolder $tFolder  /e  /r:2 /log:$ErrorLog /tee

                }
                Catch {
                        Add-Content -Path $ErrorLog  -Value "Exception write"
                        $DateTime = (Get-Date).ToShortDateString() + " " + (Get-Date).ToShortTimeString()
                        $Target = $_.TargetObject
                        $e = $_
                        Add-Content -Path $ErrorLog  -Value "$DateTime - $e $Target"
                        #Write-Host "$e $Target"
                        $ErrorActionPreference = "Continue"
                }
                 if($?)
                 {

                    add-content -path $ErrorLog -value ($?)
                 }
                 else
                 {

                     add-content -path $ErrorLog -value ($?)
                 }

             }
        }

        #write-host $accountName
    }  
    }
Catch {
        Add-Content -Path $ErrorLog  -Value "Exception write"
        $DateTime = (Get-Date).ToShortDateString() + " " + (Get-Date).ToShortTimeString()
        $Target = $_.TargetObject
        $e = $_
        Add-Content -Path $ErrorLog -force -Value "$DateTime - $e $Target"
        #Write-Host "$e $Target"
        $ErrorActionPreference = "Continue"
    }


$WorkBook.close()
$objExcel.Quit()
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($objExcel)

Can any one help me what I have to do fix the above error.

powershell
sharepoint-2010
asked on Stack Overflow Apr 4, 2014 by SP007 • edited Apr 4, 2014 by SP007

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0