Hi,
how do i get the result of a Set-RDMSession ? Is there a way of getting a return code ?
Problem is that i get a warning in the console "access denied", but how do i react to that when a script is running unattended ?
Devolutions.PowerShell version 2023.1.0.9
Hello hoppe,
You would need to set the WarningAction to Stop and use it in a Try/Catch to handle the exception. Here is a sample:
try
{
#your code...
Set-RDMSession $session -WarningAction Stop
}
catch
{
#how you want to handle the access denied
}
For more information, you can refer to https://learn.microsoft.com/en-us/powershell/scripting/learn/deep-dives/everything-about-exceptions?view=powershell-7.3
Best regards,
Richard Boisvert
Hello Richard,
I have tried your solution with a simple "Write-Output $_" in the catch clause, but nothing is written to the console.
Could you verify the the "access denied" warning raises an exception ?
Regards
Andreas
Hello Andreas,
In fact the Access denied error is displayed as a warning. There is no return code nor raise exception for this warning.
Let us know if you have further questions about this.
Best regards,
Érica Poirier