Guest User

Get-Warranty-Expiration.ps1

a guest
Dec 27th, 2013
1,454
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <#
  2. .SYNOPSIS
  3.   Author:..John
  4.   Date:....2013.12.27
  5.  
  6. .DESCRIPTION
  7.   Specify targetHost.  The script will connect and obtain the asset tag (WMI SerialNumber), and then connect to
  8.   Dell's warranty API and output general system info as well as any warranty information for non-expired warranties.
  9.  
  10. #>
  11.  
  12. $targetHost = "." # target computer
  13. $cutoffDays = 60 # write a warning for each warranty that ends sooner than this number of days
  14.  
  15. #Date/time pattern returned from Dell's API
  16. $pattern = 'yyyy\-MM\-dd\Thh\:mm\:ss'
  17.  
  18. $serialNumber = (Get-WmiObject -class Win32_SystemEnclosure -computername $targetHost -namespace "root\CIMV2").SerialNumber
  19.  
  20. $doc = New-Object System.Xml.XmlDocument
  21. $doc.Load("https://api.dell.com/support/v2/assetinfo/warranty/tags?svctags=$serialNumber&apikey=d676cf6e1e0ceb8fd14e8cb69acd812d")
  22.  
  23. write-host -NoNewLine Information for $targetHost
  24. $doc.GetAssetWarrantyResponse.GetAssetWarrantyResult.Response.DellAsset
  25.  
  26. $doc.GetAssetWarrantyResponse.GetAssetWarrantyResult.Response.DellAsset.Warranties.Warranty | ? {
  27.     [DateTime]::ParseExact($_.EndDate, $pattern, $null) -gt [DateTime]::Today
  28. } | % {
  29.     $_
  30.     $expiration = New-TimeSpan $(Get-Date) $([DateTime]::ParseExact($_.EndDate, $pattern, $null))
  31.     if ($expiration.Days -lt $cutoffDays ) {
  32.         Write-Host "Warning: warranty ends in " -ForegroundColor "yellow" -NoNewLine
  33.         Write-Host $expiration.Days -ForegroundColor "yellow" -NoNewLine
  34.         Write-Host " days" -ForegroundColor "yellow"
  35.     }  
  36. }
Advertisement
Add Comment
Please, Sign In to add comment