02-01-2021 10:12 AM
I have been working a pretty simple PowerShell script to retrieve phone data on a given device. I thought this was going to be simple but I have been hitting allot of errors when I try to run this script.
02-01-2021 12:40 PM
Can you see what's being sent "over the wire"? Either on your end, or debug level AXL logs that you extract from RTMT.
Here's a working request from my lab
POST https://chdevcucm105.nxodev.intra/axl/ HTTP/1.1 Host: chdevcucm105.nxodev.intra Authorization: Basic noneofyerbiz Connection: close Content-Type: text/xml; charset=utf-8 SOAPAction: CUCM:DB ver=11.5 getPhone Content-Length: 247 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://www.cisco.com/AXL/API/11.5"><soapenv:Header/><soapenv:Body><ns:getPhone sequence="0"> <name>CSFMTRA</name></ns:getPhone></soapenv:Body></soapenv:Envelope>
BTW... sequence you can leave out, it's optional. It's mean to correlate request/response.
02-01-2021 01:35 PM
Hey Stephan,
Thanks for your input with your suggestion I am getting a a different http 500 error "The server encountered an internal error that prevented it from fulfilling this request." I am using Soap UI to build the request and it is working as intended when I perform the query from Soap UI but when i am trying to port that over into a powershell request I am getting stumped with all kinds of errors. But thank you for your assistance.
02-01-2021 01:51 PM
It might be helpful (if you can figure out how) to get the output of the actual HTTP+XML sent out on the wire...maybe compare to a working request built with SoapUI?
This is a PS1 sample I had in my folder - might be helpful:
[System.Net.ServicePointManager]::Expect100Continue = $false $os = Get-WmiObject win32_operatingsystem $body = @' <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://www.cisco.com/AXL/API/10.5"> <soapenv:Header/> <soapenv:Body> <ns:listServiceParameter> <searchCriteria> <processNodeName>%</processNodeName> </searchCriteria> <returnedTags> <processNodeName/> <name/> <service/> <value/> <valueType/> </returnedTags> </ns:listServiceParameter> </soapenv:Body> </soapenv:Envelope> '@ $pwd = ConvertTo-SecureString "ciscopsdt" -AsPlainText -Force $cred = New-Object Management.Automation.PSCredential ('Administrator', $pwd) $Result = Invoke-RestMethod -Method Post ` -ContentType "text/xml" -Body $body ` -Credential $cred ` -Uri https://ds-ucm105.cisco.com:8443/axl/ $Result.Save('this.txt') Get-Content('this.txt')
02-03-2021 10:27 AM
So after doing more testing I found it is a problem is within the devnet environment. I made some changes to my original script to look like this:
02-03-2021 01:14 PM
You should be able to bypass certificate validation. Here's how you normally do that in a script
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true} ;
That is for Powershell running on .NET. Not sure it also works if you have a powershell running on .NET core - in my C# code on .NET core I have to go another route.
Here's a few more links on certificate issues in PowerShell: rest - Invoke-RestMethod - Ignore Self Signed Certs - Stack Overflow
02-03-2021 03:11 PM - edited 02-03-2021 03:30 PM
So now I am recieving a different error message entirely.
I am getting an Undeclated namespace prefix "soapenv". I was able to to use
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true} ;
and that seemed to fix the untrusted cert issue.
So i fiddled with the xml and Now i have zero errors. But
This is the output"
xml Envelope
--- --------
version="1.0 Envelope
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