Error in PutFileToDirectory() - How to Get Error Code?

Advertisement

aksarben
Joined:
Posts:
72

Error in PutFileToDirectory() - How to Get Error Code?

I encountered an error calling PutFileToDirectory():
try {
    $hostDirectory = Get-PathBelowWebRoot -pcRoot $pcRoot -file $file
    $remove = $false
    $session.PutFileToDirectory($file.fullName, $hostDirectory, $remove, $options)
}
catch {
    Write-Error $_
    $($_.InvocationInfo)
    exit
}
PowerShell issues the following error message:
Write-Error: Exception calling "PutFileToDirectory" with "4" argument(s): "Cannot create remote file '/C:/Users/Dick/\bib/bibliography.htm'. No such file or directory. Error code: 2 Error message from server: No such file"
This error is not unexpected, since often the target folder won't exist yet. But, how do I find the error code returned from the call? (apparently "2" in this case).

Do I have to parse error messages? I didn't see an “error code” property in the thrown exception. If the issue is simply that the target directory doesn't exist, I can create the directory & retry. But if the problem is something else, I need to know to figure out what action to take.

$PSVersionTable.Version:
Major  Minor  Patch  PreReleaseLabel BuildLabel
-----  -----  -----  --------------- ----------
7      3      4
Using the PowerShell extension to Visual Studio Code 1.79.0.

Reply with quote

Advertisement

Advertisement

You can post new topics in this forum