11-15-2017 06:28 AM
Hello, I'm attempting to change a mailbox PIN using PowerShell and I am getting an error. The error and my code is listed below. Can someone please tell me what I am doing wrong or what the error means? Thanks in advance.
--------------------------------------------------------
My code:
$RequestBody = @"
<?xml version="1.0" encoding="UTF-8"?>
<Credential>
<Credentials>newpin</Credentials>
</Credential>
"@
Invoke-WebRequest -Uri https://servername/vmrest/users/objectId/credential/pin -method Put -Body $RequestBody -ContentType 'application/json'
--------------------------------------------------------
Error:
Invoke-WebRequest :
HTTP Status 500 -
type: Exception report
message:
description: The server encountered an internal error that prevented it from fulfilling this request.
exception:
ServletException Servlet execution threw an exception
root cause:
Error Error: could not match input
note: The full stack trace of the root cause is available in the logs.
11-16-2017 10:19 AM
Is that the actual/exact content of the script?
- I believe you would replace 'objectid' in the URL with the target user's actual ID
- A pin should be numeric - you have an alpha credential 'newpin' provided
- Note you have specified 'Content-Type' as application/json but actually provided XML - i.e. application/xml
11-16-2017 10:34 AM
No. What I posted is not the exact script. I left out specfic information that would be considered confidential. All of the parameters that you listed are correct in my actual code. I updated my Content-Type to application/xml and now I get a "(400) Bad Request" error.
I'll also add that I'm testing this on my account which has sys admin privileges. I don't know if that makes a difference or not.
11-16-2017 12:34 PM
Can you also check that there is no whitespace prior to the beginning of the XML prologue ( <?xml version="1.0" encoding="UTF-8"?> )? In the example above there appears to be at least a line feed...
11-16-2017 06:11 PM
I was able to get this to work with the following script (note the PIN must be different for each test run:)
$RequestBody = @"
<?xml version="1.0" encoding="UTF-8"?>
<Credential>
<Credentials>232938236</Credentials>
</Credential>
"@
$user = 'Administrator'
$pass = 'cisco!123'
$pair = "$($user):$($pass)"
$encodedCreds = "Basic " + [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($pair))
$headers = @{ Authorization = $encodedCreds }
Invoke-WebRequest -Uri https://ds-cuc115.cisco.com/vmrest/users/5ded8079-00c7-43b4-a48d-ab55574e2dbf/credential/pin -method Put -ContentType "application/xml" -headers $Headers -Body $RequestBody
11-17-2017 03:19 AM
That worked! Thanks very much.
I have one more question. On subsequent runs I get a "(400) Bad Request)" error. Is there some type of cooldown or any other reason why I would only be able to run it once successfully? The PIN is different on each run.
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide