Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typo3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell 如何保存web服务返回的对象?_Powershell_Powershell 2.0 - Fatal编程技术网

Powershell 如何保存web服务返回的对象?

Powershell 如何保存web服务返回的对象?,powershell,powershell-2.0,Powershell,Powershell 2.0,我是PowerShell的新手,正在尝试了解如何保存(到文件或数据库)由以下web服务返回的对象: $apiKey = "00000000-1111-2222-3333-444444444444" $userName = "12345678" $password = "SamplePassword" $URI = "https://www.example.com/api/TestWS.TestService.svc?wsdl" $prox = New-WebServicePr

我是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                        : 
我想调用一个名为“chamberlist”的方法,但我很难理解它是如何工作的。是否可以将返回的对象(列表?、表格?)导出到XML/CSV/TXT/数据库?我该怎么做呢?

试试这些命令

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".
试试这些命令

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

从输出中,我认为您应该能够将方法中的值存储到变量中,您可以在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"
很难说最后一个是否有用,这取决于chambersList的内容


如果失败,请执行
$chamberlistdata |让成员
查看您可以对其执行什么操作。

从输出中,我认为您应该能够将方法中的值存储到变量中,您可以在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"
很难说最后一个是否有用,这取决于chambersList的内容

如果此操作失败,请执行
$chambersListData |让成员
查看您可以对其执行哪些操作