I'm back with another question for the lesser used function of PowerShell in this community.
I am working on an API web service call. And it appears like it is requiring a specially formatted object. I am at my wits end trying to figure out how to format or what type of object to use.
I will describe what I normally use to make web calls with parameters that do not require an object, then describe what my documentation says it needs for an object ,then maybe someone will be able to make their brain work better than mine is today.
The normal function with parameters not in an object (this is a code snippet, not the entire running code):
function Initialize-MediaroomWebServiceProxies ( [string]$wsdlRootDirectory, [string]$branchWebServiceBaseUrl ) { $Global:BSSPrincipalManagementWSP = Initialize-WebServiceProxy "$wsdlRootDirectory\latest\www.microsoft.com\iptv\bss\BSSPrincipalManagement.wsdl"; BSSPrincipalManagementNS "$branchWebServiceBaseUrl/bss/PrincipalManagement.asmx" $Global:BSS2PrincipalManagementWSP = Initialize-WebServiceProxy "$wsdlRootDirectory\latest\www.microsoft.com\iptv\bss2\BSSPrincipalManagement.wsdl"; BSS2PrincipalManagementNS "$branchWebServiceBaseUrl/bss/PrincipalManagement.asmx" $Global:OSSDiagnosticsNotificationsWSP = Initialize-WebServiceProxy "$wsdlRootDirectory\latest\www.microsoft.com\iptv\oss\Diagnostics\ossDiagnosticsNotifications.wsdl"; OSSDiagnosticsNotificationsNS "$branchWebServiceBaseUrl/ossNotificationsWS/Diagnostics.asmx" $Global:OSSBranchManagemenWSP = Initialize-WebServiceProxy "$wsdlRootDirectory\latest\www.microsoft.com\iptv\oss\branch\BranchMgmt.wsdl"; OSSBranchManagementNS "$branchWebServiceBaseUrl/ossbranch/BranchManagement.asmx" } function Send-RebootRequestToDevice ( [string]$deviceExternalId, [string]$message, [int]$timeout, [string]$reason, [bool]$forceReboot, [xml]$any ) { $OSSDiagnosticsNotificationsWSP.SendRebootRequestToDevice($deviceExternalId, $message, $timeout, $reason, $forceReboot, $any) }
Now, the first function defines the WSDL to use for the web call, and the second function is the actual web call using the defined WSDL to access the call and execute it.
For that web call "SendRebootToDevice" here is the corresponding documentation that describes how to format the parameters for the call
Parameters deviceExternalId External device ID of the set-top box to reboot. message Message the set-top box will display in a shutdown dialog box. May be null if no message is needed. timeout Number of seconds to display the shutdown dialog box. This parameter is ignored if forceReboot is true. reason Reason for the reboot. The reason is sent to the set-top box in the notification message. May be null if no reason is specified. forceReboot Boolean value specifying whether the user is notified before the reboot. If false, the reboot dialog box prompts the subscriber whether to reboot; if the user does not respond within timeout seconds, the set-top box reboots automatically. If true, the set-top box reboots immediately, and no notification is shown to the user. Any (XmlElement) Returns void
Here are the parameter requirements for the code I am attempting:
Parameters clusterName StringExternalId containing the cluster's name. Returns Array of ServiceToServerAssignment objects, specifying all associations of DServers to services on the specified cluster. This array specifies both current assignments and pending assignments that have not yet been committed.
If I setup the call the same way as the other working call that doesn't seem to need an object I get this error:
PS C:\Users\Matt Bergeron\Documents> $Objects = @() function GetServiceToServerAssignments ( [string]$clusterId ) { #$Objects += New-Object PSObject -Property @{ # ExternalId = $clusterId # } $OSSLiveDeploymentWSP.GetServiceToServerAssignments($clusterId) } PS C:\Users\Matt Bergeron\Documents> GetServiceToServerAssignments WTCVHO_ASERVCluster1 GetServiceToServerAssignments : Cannot convert argument "0", with value: "WTCVHO_ASERVCluster1", for "GetServiceToServerAssignments" to type "OSSLiveDeploymentNS.ExternalId": "Cannot convert the "WTCVHO_ASERVCluster1" valu e of type "System.String" to type "OSSLiveDeploymentNS.ExternalId"." At line:10 char:56 + $OSSLiveDeploymentWSP.GetServiceToServerAssignments <<<< ($clusterId) + CategoryInfo : NotSpecified: (:) [], MethodException + FullyQualifiedErrorId : MethodArgumentConversionInvalidCastArgument PS C:\Users\Matt Bergeron\Documents> GetServiceToServerAssignments 4F248D1A-3543-47F9-BDF6-66C48483B7C3 GetServiceToServerAssignments : Cannot convert argument "0", with value: "4F248D1A-3543-47F9-BDF6-66C48483B7C3", for "GetServiceToServerAssignments" to type "OSSLiveDeploymentNS.ExternalId": "Cannot convert the "4F248D1A-3 543-47F9-BDF6-66C48483B7C3" value of type "System.String" to type "OSSLiveDeploymentNS.ExternalId"." At line:10 char:56 + $OSSLiveDeploymentWSP.GetServiceToServerAssignments <<<< ($clusterId) + CategoryInfo : NotSpecified: (:) [], MethodException + FullyQualifiedErrorId : MethodArgumentConversionInvalidCastArgument
And lastly, Here is how I have tried to create the object, with the error message I am receiving:
PS C:\Users\Matt Bergeron\Documents> $Objects = @() function GetServiceToServerAssignments ( [string]$clusterId ) { $Objects += New-Object PSObject -Property @{ ExternalId = $clusterId } $OSSLiveDeploymentWSP.GetServiceToServerAssignments($clusterId) } PS C:\Users\Matt Bergeron\Documents> GetServiceToServerAssignments 4F248D1A-3543-47F9-BDF6-66C48483B7C3 GetServiceToServerAssignments : Cannot convert argument "0", with value: "4F248D1A-3543-47F9-BDF6-66C48483B7C3", for "GetServiceToServerAssignments" to type "OSSLiveDeploymentNS.ExternalId": "Cannot convert the "4F248D1A-3 543-47F9-BDF6-66C48483B7C3" value of type "System.String" to type "OSSLiveDeploymentNS.ExternalId"." At line:10 char:56 + $OSSLiveDeploymentWSP.GetServiceToServerAssignments <<<< ($clusterId) + CategoryInfo : NotSpecified: (:) [], MethodException + FullyQualifiedErrorId : MethodArgumentConversionInvalidCastArgument PS C:\Users\Matt Bergeron\Documents> GetServiceToServerAssignments WTCVHO_ASERVCluster1 GetServiceToServerAssignments : Cannot convert argument "0", with value: "WTCVHO_ASERVCluster1", for "GetServiceToServerAssignments" to type "OSSLiveDeploymentNS.ExternalId": "Cannot convert the "WTCVHO_ASERVCluster1" valu e of type "System.String" to type "OSSLiveDeploymentNS.ExternalId"." At line:10 char:56 + $OSSLiveDeploymentWSP.GetServiceToServerAssignments <<<< ($clusterId) + CategoryInfo : NotSpecified: (:) [], MethodException + FullyQualifiedErrorId : MethodArgumentConversionInvalidCastArgument
Sorry for the extremely long explanation, but hopefully this is enough information for someone to help me figure out what object and format it requires to run successfully.
One more thing to note. I attempt to run the command twice on each set of code. The "4F248D1A-3543-47F9-BDF6-66C48483B7C3" is the true clusterID and the "WTCVHO_ASERVCluster1" is the clusterName (I tried this just incase the externalID was the actual name of the cluster and not the cluster GUID)