title: Using PowerShell to query CRM 2011 SOAP endpoint
body: <p>I am trying to query CRM 2011 via PowerShell and SOAP. The following PowerShell script should return the Contact’s full name, but I get nothing.</p>
  
  <pre><code>$xml = "&lt;?xml version='1.0' encoding='utf-8'?&gt;"
  $xml += "&lt;soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema'&gt;"
  $xml += "&lt;soap:Body&gt;"
  $xml += "&lt;Retrieve xmlns='http://schemas.microsoft.com/xrm/2011/Contracts/Services'&gt;"
  $xml += "&lt;entityName&gt;contact&lt;/entityName&gt;"
  $xml += "&lt;id&gt;12345678-1234-1234-1234-123456789012&lt;/id&gt;"
  $xml += "&lt;columnSet xmlns:q1='http://schemas.microsoft.com/xrm/2011/Contracts' xsi:type='q1:ColumnSet'&gt;"
  $xml += "&lt;q1:Attributes&gt;"
  $xml += "&lt;q1:Attribute&gt;fullname&lt;/q1:Attribute&gt;"
  $xml += "&lt;q1:Attribute&gt;telephone1&lt;/q1:Attribute&gt;"
  $xml += "&lt;/q1:Attributes&gt;"
  $xml += "&lt;/columnSet&gt;"
  $xml += "&lt;/Retrieve&gt;&lt;/soap:Body&gt;&lt;/soap:Envelope&gt;"
  
  $url="http://crmserver.company.com/Organization/XRMServices/2011/Organization.svc/web"
  $http_request = New-Object -ComObject Msxml2.XMLHTTP
  $http_request.Open('POST', $url, $false)
  $http_request.setRequestHeader("SOAPAction",     "http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Retrieve");
  $http_request.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
  $http_request.setRequestHeader("Content-Length", $xml.length);
  $http_request.send($xml);
  $http_request.responseText
  </code></pre>
  
  <p>And here is the response:</p>
  
  <pre><code>$http_request.responseText
  
  &lt;s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"&gt;
  &lt;s:Body&gt;&lt;RetrieveResponse xmlns="http://schemas.microsoft.com/xrm/2011/Contracts/Services"&gt;
  &lt;RetrieveResult xmlns:a="http://schemas.microsoft.com/xrm/2011/Contracts" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"&gt;
  &lt;a:Attributes xmlns:b="http://schemas.datacontract.org/2004/07/System.Collections.Generic"&gt;
  &lt;a:KeyValuePairOfstringanyType&gt;
  &lt;b:key&gt;accountid&lt;/b:key&gt;
  &lt;b:value i:type="c:guid" xmlns:c="http://schemas.microsoft.com/2003/10/Serialization/"&gt;12345678-1234-1234-1234-123456789012&lt;/b:value&gt;
  &lt;/a:KeyValuePairOfstringanyType&gt;
  &lt;/a:Attributes&gt;
  &lt;a:EntityState i:nil="true"/&gt;&lt;a:FormattedValues xmlns:b="http://schemas.datacontract.org/2004/07/System.Collections.Generic"/&gt;
  &lt;a:Id&gt;12345678-1234-1234-1234-123456789012&lt;/a:Id&gt;&lt;a:LogicalName&gt;account&lt;/a:LogicalName&gt;
  &lt;a:RelatedEntities xmlns:b="http://schemas.datacontract.org/2004/07/System.Collections.Generic"/&gt;
  &lt;/RetrieveResult&gt;
  &lt;/RetrieveResponse&gt;
  </code></pre>
  
  <p>I just don’t know what I am doing wrong. Why won’t the code return “fullname”, it is in the columnSet?</p>