cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1609
Views
0
Helpful
5
Replies

Change mailbox PIN with PowerShell

tatyrell
Level 1
Level 1

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.

5 Replies 5

dstaudt
Cisco Employee
Cisco Employee

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

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.

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...

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

tatyrell
Level 1
Level 1

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.