Using PowerShell to query CRM 2011 SOAP endpoint – help!

I don’t know what I am doing wrong. All I am trying to do is to query  CRM 2011 via PowerShell and SOAP. The following PowerShell script should return the Contact’s full name, but I get nothing. Any ideas??

Here is the PowerShell:

$xml = "<?xml version='1.0' encoding='utf-8'?>"
$xml += "<soap:Envelope xmlns:soap='' xmlns:xsi='' xmlns:xsd=''>"
$xml += "<soap:Body>"
$xml += "<Retrieve xmlns=''>"
$xml += "<entityName>contact</entityName>"
$xml += "<id>12345678-1234-1234-1234-123456789012</id>"
$xml += "<columnSet xmlns:q1='' xsi:type='q1:ColumnSet'>"
$xml += "<q1:Attributes>"
$xml += "<q1:Attribute>fullname</q1:Attribute>"
$xml += "<q1:Attribute>telephone1</q1:Attribute>"
$xml += "</q1:Attributes>"
$xml += "</columnSet>"
$xml += "</Retrieve></soap:Body></soap:Envelope>"

$http_request = New-Object -ComObject Msxml2.XMLHTTP
$http_request.Open('POST', $url, $false)
$http_request.setRequestHeader("SOAPAction", "");
$http_request.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
$http_request.setRequestHeader("Content-Length", $xml.length);

And here is the response:


<s:Envelope xmlns:s="">
<s:Body><RetrieveResponse xmlns="">
<RetrieveResult xmlns:a="" xmlns:i="">
<a:Attributes xmlns:b="">
<b:value i:type="c:guid" xmlns:c="">12345678-1234-1234-1234-123456789012</b:value>
<a:EntityState i:nil="true"/><a:FormattedValues xmlns:b=""/>
<a:RelatedEntities xmlns:b=""/>

I just don’t know what I am doing wrong. Why won’t the code return “fullname”, it is in the columnSet.

Update-2012-05-08:I have posted my question here, no answer yet

Update2-2012-05-05: I have posted and received and answer here on stack overflow. Big thanks to @JLattimer


Comments are closed.