powershell
powershell copied to clipboard
[FEATURE] Connect-PnPOnline -ReturnConnection - Add Status Code
Is your feature request related to a problem? Please describe. Must wrap connection with try catch to determine if the connection attempt is successful.
Describe the solution you'd like It would be helpful if this command would return a status code of 200, 404, etc. $conn = Connect-PnPOnline -ReturnConnection
Describe alternatives you've considered Yes, I wrap the Connect-PnPOnline command in a try catch block
Additional context I can also pass invalid URLs to Connect-PnPOnline and it does NOT throw an error. It seems to connect like other valid URLs. Context checking is also invalid.
Fair point. Indeed only when you actually start doing something after connecting, it would let you know the site does not exist. We'll discuss it in the team if we can and want to change this and if so how.
I am wrong, the try catch method doesn't seem to work like I thought it would. It will just connect either way, even if invalid.
I tried wrapping Get-PnPSite in a try catch and that doesn't seem to work either. It responds with a message "Get-PnPSite: The remote server returned an error: (404) Not Found." but I can't capture that response, or pass it to a variable. Also tried the -ErrorVariable switch and that doesn't work as well.
@robertcaretta - can you please try with the latest nightly release and let us know ? We have improved the connection experience as well as added -ValidateConnection
parameter as well to check the connection.
Closing due to lack of response. The feature has been implemented, please try with the latest code, it will work.