Dell Warranty Information

So sometime in the last month or two Dell has made changes to their API. I had been using a script posted to poshcode to gather warranty information on all our workstations but that no longer works. So I figured I’d take a stab at writing it myself. Problem is, I know jack crap about parsing XML with PowerShell. I’m beyond frustrated and just looking for some guidance before I hulk-smash my desk.

Here is the uri I’m using (complete with service tag and api key): https://api.dell.com/support/v2/assetinfo/warranty/tags.xml?svctags=1763DX1&apikey=1adecee8a60444738f280aad1cd87d0e. Plug that into a browser and I get pretty pretty XML.

If I run (Invoke-WebRequest https://api.dell.com/support/v2/assetinfo/warranty/tags.xml?svctags=1763DX1&apikey=1adecee8a60444738f280aad1cd87d0e).Content it returns the XML, but I can’t figure out how to pull out the information I need - namely the warranty StartDate and EndDate.

Help?

  • Joshua

I’m learning about parsing XML at the moment also. I believe you will need to write an XPath expression and that will allow you to grab the data you need.

Hi Joshua,

Does this work for you ?

$DellResponse = Invoke-WebRequest 'https://api.dell.com/support/v2/assetinfo/warranty/tags.xml?svctags=1763DX1&apikey=1adecee8a60444738f280aad1cd87d0e'
$xml = [xml]$DellResponse

#The object way
$WarrantyDetails = $xml.GetAssetWarrantyResponse.GetAssetWarrantyResult.Response.DellAsset.Warranties.Warranty
$WarrantyEndDates = $WarrantyDetails.EndDate
$WarrantyStartDates = $WarrantyDetails.StartDate

#Or the XPath way
$WarrantyDetails = $xml.SelectNodes("*/*/*/*/*").Warranty
$WarrantyEndDates = $xml.SelectNodes("*/*/*/*/*/*").EndDate
$WarrantyStartDates = $xml.SelectNodes("*/*/*/*/*/*").StartDate

"Warranty details:"
$WarrantyDetails
"`nWarranty End Dates:"
$WarrantyEndDates
"`nWarranty Start Dates:"
$WarrantyStartDates
Warranty details:


EndDate                 : 2016-04-26T23:59:59
EntitlementType         : EXTENDED
ItemNumber              : 939-7368
ServiceLevelCode        : ND
ServiceLevelDescription : Next Business Day Support
ServiceLevelGroup       : 5
ServiceProvider         : UNY
StartDate               : 2014-04-27T00:00:00

EndDate                 : 2016-04-26T23:59:59
EntitlementType         : EXTENDED
ItemNumber              : 939-7738
ServiceLevelCode        : TS
ServiceLevelDescription : Client Gold Support / ProSupport
ServiceLevelGroup       : 8
ServiceProvider         : DELL
StartDate               : 2014-04-27T00:00:00

EndDate                 : 2014-04-26T23:59:59
EntitlementType         : INITIAL
ItemNumber              : 939-6888
ServiceLevelCode        : ND
ServiceLevelDescription : Next Business Day Support
ServiceLevelGroup       : 5
ServiceProvider         : UNY
StartDate               : 2013-04-26T00:00:00

EndDate                 : 2014-04-26T23:59:59
EntitlementType         : INITIAL
ItemNumber              : 939-7718
ServiceLevelCode        : TS
ServiceLevelDescription : Client Gold Support / ProSupport
ServiceLevelGroup       : 8
ServiceProvider         : DELL
StartDate               : 2013-04-26T00:00:00


Warranty End Dates:
2016-04-26T23:59:59
2016-04-26T23:59:59
2014-04-26T23:59:59
2014-04-26T23:59:59

Warranty Start Dates:
2014-04-27T00:00:00
2014-04-27T00:00:00
2013-04-26T00:00:00
2013-04-26T00:00:00

For XPath examples you may like to see the following webpage http://msdn.microsoft.com/en-us/library/ms256086(v=vs.110).aspx
I am learning myself XPath syntax so surely the proposal is far from perfect.

Regards,
Tomasz

Good work Tomasz, Looks so easy once someone else has done it :slight_smile:

I tried to put this together for a little bit. When I ran $xml i got the following and it i thought i was going down the wrong path and gave up since i couldn’t see any further info, didnt think to query it further.

PS C:\windows\system32> $xml

GetAssetWarrantyResponse

GetAssetWarrantyResponse

Thanks Adnan,

I tend to use get-member quite often when dealing with objects I am not familiar with.
So in this case you would run the following to get more info about the xml object

$xml | gm

I look at it now and that would be the obvious thing to of tried. Since its XML for some reason i think that threw me off and i didn’t think could try that. Going to try working with XML more as i do think its really useful for more complex data structures.

Anyway, I know for next time now :slight_smile:

thanks!

Tomasz,

That is fantastic!! I spent most of yesterday trying to figure out how to use xpath to do what I wanted. It never occurred to me to use wildcards. I kept getting stuck at $XML.SelectNodes(“/GetAssetWarrantyResponse”) and couldn’t drill down to the sub-elements.

I think I prefer the object method. It seems so much more straight forward, and obvious now that I see it. :slight_smile:

THANK YOU!!!

One question - Is there any benefit to using one over the other? The object vs xpath?

  • Joshua

Joshua,

I am happy it worked for you.
The other day when struggling with xm doc , I came across the following article. https://www.simple-talk.com/content/article.aspx?article=1917
The author made quite a nice study between xml object and Xpath methods.
Let me quote the extract:

[blockquote]"Comparison of XPath and Object Approaches

Which approach is better to access XML data? Table 1 helps you answer this question. The object approach is usually more concise (e.g. line 3), but not always (line 4). XPath, however, is more expressive, in that it allows you to specify some selectors that are not possible with object notation (line 7). However, PowerShell’s own capabilities can easily fill this gap when using object notation (line 8)."[/blockquote]

Personally I do not mind either as long as the job is done.
I guess the difference is when working at scale with a lot of data processing. Then small performance advantage from one method over the other one, can have a huge difference in long run…
You would apply measure-command to find out what works better for you.

Regards,
Tomasz