SOAP(y) Powershell fun w/ BT Diamond's IPAM (Part 2)

Since my initial attempt using New-WebServiceProxy failed because it didn't like the XML return from IPControl, I needed to find out why.  This is where I downloaded SOAPUI to dig in and find out why.  More importantly, I found that I could use the info from it to plug into the Invoke-WebRequest cmdlet.

[I'm going to be using Dell's web service as an example simply because it's easier from an example standpoint.  Dell's service actually works w/ the New-WebServiceProxy cmdlet.  The basic concept of what I'm doing is the exact same though.]



SOAPUI:

  1. Download and install SOAPUI
  2. File -> New SOAP Project
  3. In the "Initial WSDL" line, simply type in the web service's wsdl address.  I'm going to use Dell's as an example:

  4. Click OK
  5. In the left pane of the SOAPUI window, you'll find services (I guess that's what you would call them) available for you to call.  Under these should be 'methods' you can call.
    • It was also @ this point that I noticed the interface property differences between Dell and BT Diamond.  I 'think' this is why the new-webserviceproxy cmdlet had problems, but don't have any other web services to test against to know for sure.
  6. Right-click one and select "New Request" and give it whatever name you want.

  7. Now in the right pane, you should be presented w/ the XML formatted request that we can now use to pass w/ the Invoke-WebRequest cmdlet in powershell.
  8. Simply copy the XML and we're going to use it in powershell now.
Powershell:
IP Control is actually simpler since all I need to do for the GetDeviceByHostname method is provide the hostname as a string (which powershell does by default), the xml request only has one question mark in that case.  But below is the code you could use to request asset info from Dell.  Again basic concept still applies.

$WSDLURI = "http://xserv.dell.com/services/AssetService.asmx?wsdl"

# This is essentially showing how you can pass credentials to a web service that requires a login.
$Creds = Get-Credential
# I honestly don't know how to easily 'know' this beyond looking the wsdl page and looking for it.
$ApplicationName = "AssetService"
# GUID seems to be needed, I'm not sure why, but this is how you can make one fairly easily.
$GUID = [Guid]::NewGuid()
# This is the important one, you need to change this to something you are essentially looking for.
$ServiceTag = "12345678"

<# 
This the XML request that I copied from SOAPUI.  
You'll need to place escape characters (`) before quotes
#>
[xml]$XMLRequest = "
<soapenv:Envelope xmlns:soapenv=`"http://schemas.xmlsoap.org/soap/envelope/`" xmlns:web=`"http://support.dell.com/WebServices/`">
   <soapenv:Header/>
   <soapenv:Body>
      <web:GetAssetInformation>
         <web:guid>$($GUID)</web:guid>
         <!--Optional:-->
         <web:applicationName>$($ApplicationName)</web:applicationName>
         <!--Optional:-->
         <web:serviceTags>$($ServiceTag)</web:serviceTags>
      </web:GetAssetInformation>
   </soapenv:Body>
</soapenv:Envelope>"

<# 
If Dell's SOAP service required credentials, this is what the invoke-webrequest would look like.
[xml]$Result = Invoke-WebRequest -Uri $WSDLURI -Method Post -ContentType "text/xml" -Body $XMLRequest -Credential $Creds -Headers @{"SOAPAction"=" "}
BT Diamond's IPControl also requires the SOAPAction header.  Dell does not and will actually produce an error if it is included.
#>

# With all the information above, I'm now sending the request to Dell and saving the results in the $Results variable.
[xml]$Result = Invoke-WebRequest -Uri $WSDLURI -Method Post -ContentType "text/xml" -Body $XMLRequest

# Now I can simply explore the data I received by calling the $Result variable and exploring it for the information I need/want
$Result | Format-List *

In Dell's case, I would want the Entitlement data (aka warranty expiration info):
$Result.Envelope.Body.GetAssetInformationResponse.GetAssetInformationResult.Asset.Entitlements.EntitlementData

This would be the path that contains the warranty 'objects' associated w/ the service tag you searched for.  


Conclusion:
Well hope this helps someone.  It's certainly been enlightening for me.

Comments

Popular posts from this blog

NSX-T: vCenter and NSX-T Inventory out of Sync (Hosts in vSphere not showing up in NSX-T)

NSX-T: Release associated invalid node ID from certificate

MacOS: AnyConnect VPN client was unable to successfully verify the IP forwarding table modifications.