Note that there are some explanatory texts on larger screens.

plurals
  1. POCan I filter a WSDL-based SOAP query using PowerShell's New-WebServiceProxy to only send one parameter?
    text
    copied!<p>Problem: All web service calls to ServiceNow's ../cmdb_ci_win_server.do?WSDL table return zero results. </p> <p>Cause: I'm using PowerShell's New-WebServiceProxy method, which creates a .NET .dll dynamically from the WSDL definition provided by ServiceNow. The WSDL defines 174 params of which I wish to define and query against just one, but when exercised the .dll always sends the other 173 empty params in the WHERE clause of its query, which obviously results in a non-match situation. </p> <p>Hopes: The dynamic .dll lets me create a parameter object that contains the 174 params, and then lets me set properties as needed. Is it possible for me to create a similar object somehow only containing the single param I need? I've tried doing so with $param.PSObject.TypeNames.Insert(0,$paramClassName), but the resulting param object was not acceptable to the $wsproxy.getRecords($param) call. Also, I was not able to directly add a native property, only NoteProperties. Reverting to using the original param object, is it possible for me to remove 173 of the params? The underlying object seems immutable, but maybe there's some trick I've never seen?</p> <p>Demonstration code:</p> <pre><code>$cred = Get-Credential $wsproxy = New-WebServiceProxy -uri 'https://snowtest/cmdb_ci_win_server.do?WSDL' -Credential $cred if ($wsproxy) { # Force $cred onto the new wsproxy, or it will default to non-authenticated calls $wsproxy.Credentials = $cred # The parameter object we'll send with the query must be built from the custom object. # That requires we extract the class name from the method's parameter definition. # All my attempts to create a custom query object failed, including forcing the classname. $overloadDefinitions = $wsproxy.getRecords.OverloadDefinitions $paramClassName = $overloadDefinitions[0] -ireplace '^[^(]+\(([^ ]+).+$', '$1' $param = New-Object $paramClassName $param.host_name = 'ServerName' $wsproxy.getRecords($param) } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload