Error in PutFileToDirectory() - How to Get Error Code?
I encountered an error calling
PowerShell issues the following error message:
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:
Using the PowerShell extension to Visual Studio Code 1.79.0.
PutFileToDirectory()
:
try { $hostDirectory = Get-PathBelowWebRoot -pcRoot $pcRoot -file $file $remove = $false $session.PutFileToDirectory($file.fullName, $hostDirectory, $remove, $options) } catch { Write-Error $_ $($_.InvocationInfo) exit }
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).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"
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