Powershell REST request wont return server response if 404
I am still new to Powershell and haven't been able to find anything on this. I am running a REST GET request to a URI which I know for a fact returns a 404 from the server since the resource is not found.
I would like to be able to run a conditional that checks if it's a 404 and skip over it for further processing if this is the case however when I assign the request to a variable, then calling on that later, it just gives me the contents of what my request was. I have never seen anything like this before in other languages...
My basic premise is the following. I first fetch all group names, then loop through that array of names, include the current one in a new URL and make an additional request for that specific group which looks for a SHIFT which will always have the same name. If the group doesn't have that shift by name I want to skip to the next group, otherwise alter some attributes of that newly found shift object.
Here is what my code looks like, as you can see it's not acting correctly
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$user = '******'
$pass = ConvertTo-SecureString '*******' -AsPlainText -Force
$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $user, $pass
$req = Invoke-WebRequest -Credential $cred -Uri https://********-np.xmatters.com/api/xm/1/groups
$res = ConvertFrom-Json $req.Content
$content = $res.data
$base = "https://********-np.xmatters.com/api/xm/1/groups"
$group_name = $content[0].targetName
$path = "$base/$group_name/shifts/MAX-Default Shift"
$shift = Invoke-RestMethod -Credential $cred -Uri $path
Write-Host '-----------------------'
Write-Host $shift
Write-Host '-----------------------'
... RESPONSE BELOW ....
Invoke-RestMethod : The remote server returned an error: (404) Not Found.
At \MMFILE********$MyDocumentsGroup Supers PReliminary.ps1:16 char:10
+ $shift = Invoke-RestMethod -Credential $cred -Uri $path
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
-----------------------
@id=***********; group=; name=MAX-Default Shift; description="; start=2018-08-21T04:00:00.000Z; end=2018-08-22T04:00:00.000Z; timezone=America/New_York; recurrence=;
links=
-----------------------
PS C:WINDOWSsystem32>
What I would like to do is something like, in shorthand code, if $shift.code == 404 ... skip ... else ... run additional query
json powershell httprequest response
add a comment |
I am still new to Powershell and haven't been able to find anything on this. I am running a REST GET request to a URI which I know for a fact returns a 404 from the server since the resource is not found.
I would like to be able to run a conditional that checks if it's a 404 and skip over it for further processing if this is the case however when I assign the request to a variable, then calling on that later, it just gives me the contents of what my request was. I have never seen anything like this before in other languages...
My basic premise is the following. I first fetch all group names, then loop through that array of names, include the current one in a new URL and make an additional request for that specific group which looks for a SHIFT which will always have the same name. If the group doesn't have that shift by name I want to skip to the next group, otherwise alter some attributes of that newly found shift object.
Here is what my code looks like, as you can see it's not acting correctly
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$user = '******'
$pass = ConvertTo-SecureString '*******' -AsPlainText -Force
$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $user, $pass
$req = Invoke-WebRequest -Credential $cred -Uri https://********-np.xmatters.com/api/xm/1/groups
$res = ConvertFrom-Json $req.Content
$content = $res.data
$base = "https://********-np.xmatters.com/api/xm/1/groups"
$group_name = $content[0].targetName
$path = "$base/$group_name/shifts/MAX-Default Shift"
$shift = Invoke-RestMethod -Credential $cred -Uri $path
Write-Host '-----------------------'
Write-Host $shift
Write-Host '-----------------------'
... RESPONSE BELOW ....
Invoke-RestMethod : The remote server returned an error: (404) Not Found.
At \MMFILE********$MyDocumentsGroup Supers PReliminary.ps1:16 char:10
+ $shift = Invoke-RestMethod -Credential $cred -Uri $path
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
-----------------------
@id=***********; group=; name=MAX-Default Shift; description="; start=2018-08-21T04:00:00.000Z; end=2018-08-22T04:00:00.000Z; timezone=America/New_York; recurrence=;
links=
-----------------------
PS C:WINDOWSsystem32>
What I would like to do is something like, in shorthand code, if $shift.code == 404 ... skip ... else ... run additional query
json powershell httprequest response
Yes, this is an unfortunate reality about theInvoke-*
web cmdlets. If you do not get content and instead get a non-success code, they throw an error.
– TheIncorrigible1
Nov 13 '18 at 14:42
Any way around this?
– M_A87
Nov 13 '18 at 14:47
Using-ErrorAction Stop
to force it into being a terminating error and use atry/catch
block.
– TheIncorrigible1
Nov 13 '18 at 14:55
add a comment |
I am still new to Powershell and haven't been able to find anything on this. I am running a REST GET request to a URI which I know for a fact returns a 404 from the server since the resource is not found.
I would like to be able to run a conditional that checks if it's a 404 and skip over it for further processing if this is the case however when I assign the request to a variable, then calling on that later, it just gives me the contents of what my request was. I have never seen anything like this before in other languages...
My basic premise is the following. I first fetch all group names, then loop through that array of names, include the current one in a new URL and make an additional request for that specific group which looks for a SHIFT which will always have the same name. If the group doesn't have that shift by name I want to skip to the next group, otherwise alter some attributes of that newly found shift object.
Here is what my code looks like, as you can see it's not acting correctly
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$user = '******'
$pass = ConvertTo-SecureString '*******' -AsPlainText -Force
$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $user, $pass
$req = Invoke-WebRequest -Credential $cred -Uri https://********-np.xmatters.com/api/xm/1/groups
$res = ConvertFrom-Json $req.Content
$content = $res.data
$base = "https://********-np.xmatters.com/api/xm/1/groups"
$group_name = $content[0].targetName
$path = "$base/$group_name/shifts/MAX-Default Shift"
$shift = Invoke-RestMethod -Credential $cred -Uri $path
Write-Host '-----------------------'
Write-Host $shift
Write-Host '-----------------------'
... RESPONSE BELOW ....
Invoke-RestMethod : The remote server returned an error: (404) Not Found.
At \MMFILE********$MyDocumentsGroup Supers PReliminary.ps1:16 char:10
+ $shift = Invoke-RestMethod -Credential $cred -Uri $path
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
-----------------------
@id=***********; group=; name=MAX-Default Shift; description="; start=2018-08-21T04:00:00.000Z; end=2018-08-22T04:00:00.000Z; timezone=America/New_York; recurrence=;
links=
-----------------------
PS C:WINDOWSsystem32>
What I would like to do is something like, in shorthand code, if $shift.code == 404 ... skip ... else ... run additional query
json powershell httprequest response
I am still new to Powershell and haven't been able to find anything on this. I am running a REST GET request to a URI which I know for a fact returns a 404 from the server since the resource is not found.
I would like to be able to run a conditional that checks if it's a 404 and skip over it for further processing if this is the case however when I assign the request to a variable, then calling on that later, it just gives me the contents of what my request was. I have never seen anything like this before in other languages...
My basic premise is the following. I first fetch all group names, then loop through that array of names, include the current one in a new URL and make an additional request for that specific group which looks for a SHIFT which will always have the same name. If the group doesn't have that shift by name I want to skip to the next group, otherwise alter some attributes of that newly found shift object.
Here is what my code looks like, as you can see it's not acting correctly
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$user = '******'
$pass = ConvertTo-SecureString '*******' -AsPlainText -Force
$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $user, $pass
$req = Invoke-WebRequest -Credential $cred -Uri https://********-np.xmatters.com/api/xm/1/groups
$res = ConvertFrom-Json $req.Content
$content = $res.data
$base = "https://********-np.xmatters.com/api/xm/1/groups"
$group_name = $content[0].targetName
$path = "$base/$group_name/shifts/MAX-Default Shift"
$shift = Invoke-RestMethod -Credential $cred -Uri $path
Write-Host '-----------------------'
Write-Host $shift
Write-Host '-----------------------'
... RESPONSE BELOW ....
Invoke-RestMethod : The remote server returned an error: (404) Not Found.
At \MMFILE********$MyDocumentsGroup Supers PReliminary.ps1:16 char:10
+ $shift = Invoke-RestMethod -Credential $cred -Uri $path
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
-----------------------
@id=***********; group=; name=MAX-Default Shift; description="; start=2018-08-21T04:00:00.000Z; end=2018-08-22T04:00:00.000Z; timezone=America/New_York; recurrence=;
links=
-----------------------
PS C:WINDOWSsystem32>
What I would like to do is something like, in shorthand code, if $shift.code == 404 ... skip ... else ... run additional query
json powershell httprequest response
json powershell httprequest response
asked Nov 13 '18 at 14:37
M_A87M_A87
76
76
Yes, this is an unfortunate reality about theInvoke-*
web cmdlets. If you do not get content and instead get a non-success code, they throw an error.
– TheIncorrigible1
Nov 13 '18 at 14:42
Any way around this?
– M_A87
Nov 13 '18 at 14:47
Using-ErrorAction Stop
to force it into being a terminating error and use atry/catch
block.
– TheIncorrigible1
Nov 13 '18 at 14:55
add a comment |
Yes, this is an unfortunate reality about theInvoke-*
web cmdlets. If you do not get content and instead get a non-success code, they throw an error.
– TheIncorrigible1
Nov 13 '18 at 14:42
Any way around this?
– M_A87
Nov 13 '18 at 14:47
Using-ErrorAction Stop
to force it into being a terminating error and use atry/catch
block.
– TheIncorrigible1
Nov 13 '18 at 14:55
Yes, this is an unfortunate reality about the
Invoke-*
web cmdlets. If you do not get content and instead get a non-success code, they throw an error.– TheIncorrigible1
Nov 13 '18 at 14:42
Yes, this is an unfortunate reality about the
Invoke-*
web cmdlets. If you do not get content and instead get a non-success code, they throw an error.– TheIncorrigible1
Nov 13 '18 at 14:42
Any way around this?
– M_A87
Nov 13 '18 at 14:47
Any way around this?
– M_A87
Nov 13 '18 at 14:47
Using
-ErrorAction Stop
to force it into being a terminating error and use a try/catch
block.– TheIncorrigible1
Nov 13 '18 at 14:55
Using
-ErrorAction Stop
to force it into being a terminating error and use a try/catch
block.– TheIncorrigible1
Nov 13 '18 at 14:55
add a comment |
2 Answers
2
active
oldest
votes
You could suppress the error message via Try..Catch
and in so doing allow the script to continue:
Try
$Shift = Invoke-RestMethod http://www.google.com/fakeurl -ErrorAction Stop
#Do other things here if the URL exists..
Catch
if ($_.Exception -eq 'The remote server returned an error: (404) Not Found.')
#Do other things here that you want to happen if the URL does not exist..
Note this will hide all terminating errors from Invoke-ResetMethod
. You could then use an if
statement to see if the exception was a 404 and then perform further actions accordingly.
Yea, but like I said earlier I want to run additional requests, this time a PUT request, but only if the resource exists, so there isn't anything to catch, right? Catching would be if it failed. In that case my other stuff would go in the TRY block, which would break if the request failed.
– M_A87
Nov 13 '18 at 14:53
Updated my answer. Does that help?
– Mark Wragg
Nov 13 '18 at 15:00
Yes, things you want to happen if an exception doesn't occur should go in theTry
. These lines won't be executed when there is a 404 as the code will jump to thecatch
as soon as an exception occurs.
– Mark Wragg
Nov 13 '18 at 15:02
add a comment |
You need to use a try ... catch.
$code = ""
try
$shift = Invoke-RestMethod -Credential $cred -Uri $path
catch
$code = $_.Exception.Response.StatusCode.value__
if($code -eq "404")
continue
# Other things
else
Write-Host '-----------------------'
Write-Host $shift
Write-Host '-----------------------'
Thank you. Works good
– M_A87
Nov 13 '18 at 15:06
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53283382%2fpowershell-rest-request-wont-return-server-response-if-404%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You could suppress the error message via Try..Catch
and in so doing allow the script to continue:
Try
$Shift = Invoke-RestMethod http://www.google.com/fakeurl -ErrorAction Stop
#Do other things here if the URL exists..
Catch
if ($_.Exception -eq 'The remote server returned an error: (404) Not Found.')
#Do other things here that you want to happen if the URL does not exist..
Note this will hide all terminating errors from Invoke-ResetMethod
. You could then use an if
statement to see if the exception was a 404 and then perform further actions accordingly.
Yea, but like I said earlier I want to run additional requests, this time a PUT request, but only if the resource exists, so there isn't anything to catch, right? Catching would be if it failed. In that case my other stuff would go in the TRY block, which would break if the request failed.
– M_A87
Nov 13 '18 at 14:53
Updated my answer. Does that help?
– Mark Wragg
Nov 13 '18 at 15:00
Yes, things you want to happen if an exception doesn't occur should go in theTry
. These lines won't be executed when there is a 404 as the code will jump to thecatch
as soon as an exception occurs.
– Mark Wragg
Nov 13 '18 at 15:02
add a comment |
You could suppress the error message via Try..Catch
and in so doing allow the script to continue:
Try
$Shift = Invoke-RestMethod http://www.google.com/fakeurl -ErrorAction Stop
#Do other things here if the URL exists..
Catch
if ($_.Exception -eq 'The remote server returned an error: (404) Not Found.')
#Do other things here that you want to happen if the URL does not exist..
Note this will hide all terminating errors from Invoke-ResetMethod
. You could then use an if
statement to see if the exception was a 404 and then perform further actions accordingly.
Yea, but like I said earlier I want to run additional requests, this time a PUT request, but only if the resource exists, so there isn't anything to catch, right? Catching would be if it failed. In that case my other stuff would go in the TRY block, which would break if the request failed.
– M_A87
Nov 13 '18 at 14:53
Updated my answer. Does that help?
– Mark Wragg
Nov 13 '18 at 15:00
Yes, things you want to happen if an exception doesn't occur should go in theTry
. These lines won't be executed when there is a 404 as the code will jump to thecatch
as soon as an exception occurs.
– Mark Wragg
Nov 13 '18 at 15:02
add a comment |
You could suppress the error message via Try..Catch
and in so doing allow the script to continue:
Try
$Shift = Invoke-RestMethod http://www.google.com/fakeurl -ErrorAction Stop
#Do other things here if the URL exists..
Catch
if ($_.Exception -eq 'The remote server returned an error: (404) Not Found.')
#Do other things here that you want to happen if the URL does not exist..
Note this will hide all terminating errors from Invoke-ResetMethod
. You could then use an if
statement to see if the exception was a 404 and then perform further actions accordingly.
You could suppress the error message via Try..Catch
and in so doing allow the script to continue:
Try
$Shift = Invoke-RestMethod http://www.google.com/fakeurl -ErrorAction Stop
#Do other things here if the URL exists..
Catch
if ($_.Exception -eq 'The remote server returned an error: (404) Not Found.')
#Do other things here that you want to happen if the URL does not exist..
Note this will hide all terminating errors from Invoke-ResetMethod
. You could then use an if
statement to see if the exception was a 404 and then perform further actions accordingly.
edited Nov 13 '18 at 14:59
answered Nov 13 '18 at 14:49
Mark WraggMark Wragg
14.9k42146
14.9k42146
Yea, but like I said earlier I want to run additional requests, this time a PUT request, but only if the resource exists, so there isn't anything to catch, right? Catching would be if it failed. In that case my other stuff would go in the TRY block, which would break if the request failed.
– M_A87
Nov 13 '18 at 14:53
Updated my answer. Does that help?
– Mark Wragg
Nov 13 '18 at 15:00
Yes, things you want to happen if an exception doesn't occur should go in theTry
. These lines won't be executed when there is a 404 as the code will jump to thecatch
as soon as an exception occurs.
– Mark Wragg
Nov 13 '18 at 15:02
add a comment |
Yea, but like I said earlier I want to run additional requests, this time a PUT request, but only if the resource exists, so there isn't anything to catch, right? Catching would be if it failed. In that case my other stuff would go in the TRY block, which would break if the request failed.
– M_A87
Nov 13 '18 at 14:53
Updated my answer. Does that help?
– Mark Wragg
Nov 13 '18 at 15:00
Yes, things you want to happen if an exception doesn't occur should go in theTry
. These lines won't be executed when there is a 404 as the code will jump to thecatch
as soon as an exception occurs.
– Mark Wragg
Nov 13 '18 at 15:02
Yea, but like I said earlier I want to run additional requests, this time a PUT request, but only if the resource exists, so there isn't anything to catch, right? Catching would be if it failed. In that case my other stuff would go in the TRY block, which would break if the request failed.
– M_A87
Nov 13 '18 at 14:53
Yea, but like I said earlier I want to run additional requests, this time a PUT request, but only if the resource exists, so there isn't anything to catch, right? Catching would be if it failed. In that case my other stuff would go in the TRY block, which would break if the request failed.
– M_A87
Nov 13 '18 at 14:53
Updated my answer. Does that help?
– Mark Wragg
Nov 13 '18 at 15:00
Updated my answer. Does that help?
– Mark Wragg
Nov 13 '18 at 15:00
Yes, things you want to happen if an exception doesn't occur should go in the
Try
. These lines won't be executed when there is a 404 as the code will jump to the catch
as soon as an exception occurs.– Mark Wragg
Nov 13 '18 at 15:02
Yes, things you want to happen if an exception doesn't occur should go in the
Try
. These lines won't be executed when there is a 404 as the code will jump to the catch
as soon as an exception occurs.– Mark Wragg
Nov 13 '18 at 15:02
add a comment |
You need to use a try ... catch.
$code = ""
try
$shift = Invoke-RestMethod -Credential $cred -Uri $path
catch
$code = $_.Exception.Response.StatusCode.value__
if($code -eq "404")
continue
# Other things
else
Write-Host '-----------------------'
Write-Host $shift
Write-Host '-----------------------'
Thank you. Works good
– M_A87
Nov 13 '18 at 15:06
add a comment |
You need to use a try ... catch.
$code = ""
try
$shift = Invoke-RestMethod -Credential $cred -Uri $path
catch
$code = $_.Exception.Response.StatusCode.value__
if($code -eq "404")
continue
# Other things
else
Write-Host '-----------------------'
Write-Host $shift
Write-Host '-----------------------'
Thank you. Works good
– M_A87
Nov 13 '18 at 15:06
add a comment |
You need to use a try ... catch.
$code = ""
try
$shift = Invoke-RestMethod -Credential $cred -Uri $path
catch
$code = $_.Exception.Response.StatusCode.value__
if($code -eq "404")
continue
# Other things
else
Write-Host '-----------------------'
Write-Host $shift
Write-Host '-----------------------'
You need to use a try ... catch.
$code = ""
try
$shift = Invoke-RestMethod -Credential $cred -Uri $path
catch
$code = $_.Exception.Response.StatusCode.value__
if($code -eq "404")
continue
# Other things
else
Write-Host '-----------------------'
Write-Host $shift
Write-Host '-----------------------'
answered Nov 13 '18 at 14:59
ShrewkRootShrewkRoot
111
111
Thank you. Works good
– M_A87
Nov 13 '18 at 15:06
add a comment |
Thank you. Works good
– M_A87
Nov 13 '18 at 15:06
Thank you. Works good
– M_A87
Nov 13 '18 at 15:06
Thank you. Works good
– M_A87
Nov 13 '18 at 15:06
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53283382%2fpowershell-rest-request-wont-return-server-response-if-404%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Yes, this is an unfortunate reality about the
Invoke-*
web cmdlets. If you do not get content and instead get a non-success code, they throw an error.– TheIncorrigible1
Nov 13 '18 at 14:42
Any way around this?
– M_A87
Nov 13 '18 at 14:47
Using
-ErrorAction Stop
to force it into being a terminating error and use atry/catch
block.– TheIncorrigible1
Nov 13 '18 at 14:55