2011-08-17 71 views
1

我是新來的PowerShell,我試圖找出如何保存(到文件或數據庫)由以下Web服務返回的對象:如何保存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 /數據庫?我怎樣才能做到這一點?

回答

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" 

很難說是否最後有用,取決於商會的內容列表

如果失敗,請執行$chambersListData | Get-Member以查看您可以對其執行哪些操作。

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". 

和出口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".