I want to make script to check our local apps I do not have permission to all of them but I just want to get the status of each app
I use this command
Invoke-WebRequest -Uri $WEBAPP -Method get | select statuscode
when I send the request for the apps I do not have access I got this error
Invoke-WebRequest : Server Error
401 - Unauthorized: Access is denied due to invalid credentials.
You do not have permission to view this directory or page using the credentials that you supplied.
At line:1 char:1
+ Invoke-WebRequest -Uri $WEBAPP -Method get | select statuscode
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
I know I just want to get 401 under status code instead of this complete error , I do agree with powershell I do not have access
I have come up with this issue before. Unfortunately its always going to error rather than just return the error code. When I was investigating it, I came across this post of Stack Overflow which solved it for me: