1

I am attempting to send a hashmap to a Java API in PowerShell. I need to create a hashmap for one of the inputs required. I am able to create a hashtable via the following method:

$myMap = @{"name1" = "server1"; "name2" = "server2"}

We then echo that and get...

    echo $mymap
System.Collections.Hashtable

How can I convert the System.Collections.Hashtable object to a hashmap within Powershell? Attempting to send it as a hashtable returns this error:

Cannot convert argument "in0", with value: "System.Collections.Hashtable", for "search" to type "SiteScope.Map": "Cannot create object of type "SiteScope.Map". The path property was not found for the SiteScope.Map object. The available property is: [item <SiteScope.mapItem[]>]" At line:6 char:5 +     $ssWs.search($myMap,"5","$strUsername", "$strPassword","1") +     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (:) [], MethodException
+ FullyQualifiedErrorId : MethodArgumentConversionInvalidCastArgument

"SiteScope" is the Java application with the API.

jpaugh
  • 6,634
  • 4
  • 38
  • 90
tm77
  • 21
  • 4
  • 1
    Java doesn't have `System.Collections.Hashtable`... What Java API do you believe you have access to from ".Net", and why do you think that? – Elliott Frisch Jan 07 '14 at 16:03
  • 3
    You cannot use Java classes from a .Net language (PowerShell), but you could output as JSON (http://stackoverflow.com/questions/8419609/how-can-i-convert-a-hastable-to-a-json-string-in-powershell), then use Java to convert the JSON to a HashMap (http://stackoverflow.com/questions/443499/json-to-map) – Rynant Jan 07 '14 at 16:31
  • Elliott, I am using .Net to send a few strings, an integer, and if I can figure it out, a hashmap to the API via a WSDL service. I have successfully run other API calls that don't require a Hashmap (only strings and integers). System.Collections.Hashtable is a PowerShell object. – tm77 Jan 07 '14 at 16:40
  • Thanks Rynant, I will dig into that. I have almost zero non-GUI Java experience, but when I resolve my issue, I will post the resolution. – tm77 Jan 07 '14 at 16:44
  • @tm77, a lack of experience with non-GUI applications should have no bearing on your ability (or lack thereof) to use and manipulate appropriate data structures. – alroc Jan 07 '14 at 17:41
  • @alroc, We don't all have the same experience with the same technologies. If you don't have any value to add to this discussion, then nobody benefits from you commenting on it. – tm77 Jan 07 '14 at 21:00
  • @tm77 WSDLs are language-independent, so the fact that the API is written in Java is (hopefully) irrelevant. You should (probably) replace all references to java in your question with "a WSDL service", to hopefully get targeted answers. – jpaugh Feb 09 '17 at 15:12
  • @tm77 Also, read alroc's comment again. He's encouraging you that "non-GUI" experience is neither required nor preferred. Why are you upset about that? – jpaugh Feb 09 '17 at 15:13
  • The relevant data structure is a map. Not a hashmap or a hashtable. Hashmaps are unnecessary implementation detail in this question. You have a map (that happens to be a hashtable) and you want to turn it into a WSDL map. Read https://www.w3.org/2005/07/xml-schema-patterns.html#Maps – Klitos Kyriacou Feb 09 '17 at 15:20

0 Answers0