admin管理员组

文章数量:1399287

I use The following powershell code to copy file from a remote machine on the same network to the actual machine where this powershell is executed. The firewall is disabled. The $UpdateSourceFolder is a shared folder where all users have access. The problem is that copy-item never returns me exception but the file are not copied from one location to another.

Try {
    Copy-item "$UpdateSourceFolder\*" "$UpdateDestinationFolder" -Force -Recurse -ErrorAction Stop
    Add-Content $LogFilePath "SUCCESSFULLY COPIED FILE"
}
catch {
    $errorMessage = $_.Exception.Message 
    Add-Content $LogFilePath $errorMessage
}

Is there something I can do to force Powershell to give me the exception?

本文标签: Powershell CopyItem fails without exceptionsStack Overflow