我是PowerShell的新手,我正在试图弄清楚如何保存(到文件或数据库)以下Web服务返回的对象:
$apiKey = "00000000-1111-2222-3333-444444444444"
$userName = "12345678"
$password = "SamplePassword"
$URI = "https://www.example.com/api/TestWS.TestService.svc?wsdl"
$prox = New-WebServiceProxy -uri $URI -namespace WebServiceProxy
$prox.chambersList
$prox.chambersList($userName, $password, $apiKey, 0, $false, 0, $false)
---------------------------------------------------------------------
MemberType : Method
OverloadDefinitions : {WebServiceProxy.chambersListOutputData, ijfah16c, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null chambersList(string userName, string password, string apiKey, System.Nullable[int] pageNumber, bool pageNumberSpecified, System.Nullable[int] pageSize, bool pageSizeSpecified)}
TypeNameOfValue : System.Management.Automation.PSMethod
Value : WebServiceProxy.chambersListOutputData, ijfah16c, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null chambersList(string userName, string password, string apiKey, System.Nullable[int] pageNumber, bool pageNumberSpecified, System.Nullable[int] pageSize, bool pageSizeSpecified)
Name : chambersList
IsInstance : True
chambersList : {797, 798, 799, 800...}
pagesCount : 92
pagesCountSpecified : True
allElementsCount : 918
allElementsCountSpecified : True
pageNumber : 1
pageNumberSpecified : True
pageSize : 10
pageSizeSpecified : True
description : OK
code : OK
codeSpecified : True
information :
我想调用一个名为“chambersList”的方法,但我无法理解它是如何工作的。是否可以将返回的对象(List?,Table?)导出到XML / CSV / TXT /数据库?我怎么能这样做?
答案 0 :(得分:1)
从输出中,我得知你应该能够将方法中的值存储到变量中,您可以在Powershell中执行您喜欢的操作:
$chambersListData = $prox.chambersList($userName, $password, $apiKey, 0, $false, 0, $false)
#Just an example of using the data
if ($chambersListData.allElementsCountSpecified)
{
$chambersListData.allElementsCount
}
$chambersListData.chambersList | Foreach-Object {
#do something with the elements
}
$chambersListData.chambersList | Export-Csv "myChambersList.csv"
很难判断最后一个是否有用,取决于chamberList的内容
如果失败,请执行$chambersListData | Get-Member
查看您可以使用它做什么。
答案 1 :(得分:0)
尝试这些命令
Get-command -verb export
然后返回每个命令:
Help export-....
通常,您会将变量传递给命令:
$prox.chambersList($userName, $password, $apiKey, 0, $false, 0, $false) | export-...
导出的方法很少,csv和 clixml(基本上就是PowerShell对象)听起来像你想要的东西。 当然这取决于你之后想做什么?
还可以在此处查看更详细的帮助:
To see the examples, type: "get-help Export-CSV -examples".
For more information, type: "get-help Export-CSV -detailed".
For technical information, type: "get-help Export-CSV -full".
和export-clixml
To see the examples, type: "get-help Export-Clixml -examples".
For more information, type: "get-help Export-Clixml -detailed".
For technical information, type: "get-help Export-Clixml -full".