我正在尝试编写Powershell脚本以与Microsoft API一起使用,并且对此感到陌生,我遇到了一个我似乎无法克服的错误。
错误:
Cannot find an overload for "UpdateDeviceValues" and the argument count: "3". At C:\PowerShellScripts\API-UpdateDeviceValues-ICC.ps1:13 char:37 + $accounts = $pmws.UpdateDeviceValues <<<< ('18B81F1FD790','DisableICC','True'); + CategoryInfo : NotSpecified: (:) [], MethodException + FullyQualifiedErrorId : MethodCountCouldNotFindBest
从我的搜索看来,该API要求向其发送三个值,但这就是我要发送的内容。
我的代码:
$pmws = New-Object PrincipalManagement;
$pmws.Credentials = $cred;
$pmws.url = "http://172.31.9.2/bss/PrincipalManagement.asmx";
$accounts = $pmws.UpdateDeviceValues('18B81F1FD790','DisableICC','True');
$accounts
任何有关此错误的帮助将不胜感激。我对此很陌生,让Powershell与API一起使用。
这是API的SOAP 1.1示例。
POST /bss/PrincipalManagement.asmx HTTP/1.1
Host: 172.31.9.2
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://www.microsoft.com/iptv/bss/UpdateDeviceValues"
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope">
<soap:Body>
<UpdateDeviceValues xmlns="http://www.microsoft.com/iptv/bss">
<deviceExternalID>string</deviceExternalID>
<deviceValues>
<DeviceValue Key="string" Value="string" />
<DeviceValue Key="string" Value="string" />
</deviceValues>
</UpdateDeviceValues>
</soap:Body>
</soap:Envelope>
我可以在PowerShell中运行它:
> $pmws | Get-Member
我得到了很长的API列表,其中是我要使用的API ...
TypeName:委托人管理
名称-MemberType-定义
UpdateDeviceValues-方法-System.Void UpdateDeviceValues(字符串deviceExternalID,DeviceValue [] deviceValues)
非常感谢Chamele0n!找到答案! 我不知道如何在调用方法时正确格式化参数。 可行!
$Account = "18B81F1FD790"
$deviceValue = New-Object ($ns + ".DeviceValue")
$deviceValue.Key = "DisableICC"
$deviceValue.Value = "True"
$accounts = $pmws.UpdateDeviceValues($Account, $deviceValue)
谢谢, 杰森...