問題: ServiceNow の ../cmdb_ci_win_server.do?WSDL テーブルへのすべての Web サービス呼び出しがゼロの結果を返します。
原因: PowerShell の New-WebServiceProxy メソッドを使用しています。このメソッドは、ServiceNow によって提供される WSDL 定義から動的に .NET .dll を作成します。WSDL は 174 個のパラメーターを定義し、そのうちの 1 つだけを定義してクエリを実行しますが、.dll を実行すると、クエリの WHERE 句で他の 173 個の空のパラメーターが常に送信され、明らかに一致しない状況が発生します。
希望: 動的な .dll を使用すると、174 個のパラメーターを含むパラメーター オブジェクトを作成でき、必要に応じてプロパティを設定できます。必要な単一のパラメーターのみを含む同様のオブジェクトを何らかの方法で作成することは可能ですか? 私は $param.PSObject.TypeNames.Insert(0,$paramClassName) でそうしようとしましたが、結果の param オブジェクトは $wsproxy.getRecords($param) 呼び出しに受け入れられませんでした。また、ネイティブ プロパティを直接追加することはできませんでした。NoteProperties のみです。元の param オブジェクトを使用するように戻しましたが、173 個の param を削除することはできますか? 基になるオブジェクトは不変のようですが、見たことのないトリックがあるのではないでしょうか?
デモコード:
$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)
}