Get-DellSupportInfo.ps1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 |
#requires -Version 3.0 -Modules core <#PSScriptInfo .VERSION 0.3 .GUID 516711c1-bcf1-4e8a-ac7e-4cf33f16ff4b .AUTHOR Chris Masters .COMPANYNAME Chris Masters .COPYRIGHT (c) 2016 Chris Masters. All rights reserved. .TAGS system warranty dell support techdirect .LICENSEURI .PROJECTURI https://www.powershellgallery.com/profiles/masters274/ .ICONURI .EXTERNALMODULEDEPENDENCIES core .REQUIREDSCRIPTS .EXTERNALSCRIPTDEPENDENCIES .RELEASENOTES 11/14/2016: 0.2 - Fixed mapping issues for LOB & Description - Added a switch param to use the sandbox environment. Default is production - Reversed if statement 0.3 - Added link to get your TechDirect account setup, and request a key .PRIVATEDATA Setup your TechDirect account, and request your API key from https://techdirect.dell.com/portal/AboutAPIs.aspx #> <# .SYNOPSIS Get warranty and support information about Dell systems. .DESCRIPTION Allows you to take the service tag information from all of your Dell assets, and get the support information for each. This save many hours when you have hundreds or thousands of Dell devices. .EXAMPLE ./GetDellSupportInfo.ps1 -ApiKey '1234567890' -ServiceTag ('abc1234',def5678') This will return the support information about both service tags provided. .NOTES Requires that you have a valid API key from TechDirect for warranty lookup. .LINK https://github.com/masters274/ https://techdirect.dell.com/portal/AboutAPIs.aspx .INPUTS Accepts a string value for API key and a string or array of strings for the ServiceTag parameter .OUTPUTS Provides PSObject with system information for each service tag. #> [CmdletBinding()] Param ( [Parameter(Mandatory=$true,ValueFromPipeline=$true, HelpMessage='ServiceTag of Dell device', Position=0)] [Alias('st')] [String[]]$ServiceTag, [Parameter(Mandatory=$true, HelpMessage='API key from Dell TechDirect', Position=1)] [Alias('ak','api')] [String]$ApiKey, [Parameter(HelpMessage='Use Dell sandbox?', Position=2)] [Switch]$Dev ) Begin { $scriptVersion = 'Dell Support Info Grabber version 0.2' Write-Output -InputObject $scriptVersion # Check for requirements Try { Write-Debug -Message 'Checking for prerequisites' Test-ModuleLoaded -RequiredModules ('core') -Quiet | Out-Null } Catch { Write-Debug -Message 'If you made it here, you do not have the Core module available to check requirements' Write-Error -Message 'Core module not loaded! Failed to test requirements.' } } Process { # Get a baseline snapshot Write-Debug -Message 'Creating a variable snapshot' Write-Debug -Message 'Processing the script...' # Variables if ($Dev) { $strDomainName = 'sandbox.api.dell.com' } Else { $strDomainName = 'api.dell.com' } $strBaseUri = ('https://{0}/support/assetinfo/v4/' -f $strDomainName) $arrayMethods = ('GetAssetHeader','GetAssetWarranty','GetAssetSummary','GetCodeMapping') $strContentType = 'Application/xml' $objReportData = @() Foreach ($system in $ServiceTag) { # Verify that we have a valid service tag if ($system.Length -ne 7) { Write-Error -Message ('Service Tag {0} is invalid!' -f $system) } $strUri = ('{0}/{1}/{2}?apikey={3}' -f $strBaseUri,$arrayMethods[2],$system,$ApiKey) Write-Debug -Message ('URI: {0}' -f $strUri) Try { $rawRequest = Invoke-WebRequest -Uri $strUri -ContentType $strContentType -Method Get ` -ErrorVariable $wrev } Catch { Write-Error -Message ('Something went wrong connecting to {0}' -f $strBaseUri) } If (!($wrev.Count -gt 0)) { [xml]$xmlContent = $rawRequest.Content $objBuilder = New-Object -TypeName PSObject $objBuilder | Add-Member -MemberType NoteProperty -Name 'ServiceTag' -Value ( '{0}' -f $xmlContent.AssetSummaryDTO.AssetSummaryResponse.AssetHeaderData.ServiceTag ) $objBuilder | Add-Member -MemberType NoteProperty -Name 'CustomerNumber' -Value ( '{0}' -f $xmlContent.AssetSummaryDTO.AssetSummaryResponse.AssetHeaderData.CustomerNumber ) $objBuilder | Add-Member -MemberType NoteProperty -Name 'OrderNumber' -Value ( '{0}' -f $xmlContent.AssetSummaryDTO.AssetSummaryResponse.AssetHeaderData.OrderNumber ) $objBuilder | Add-Member -MemberType NoteProperty -Name 'LOB' -Value ( '{0}' -f $xmlContent.AssetSummaryDTO.AssetSummaryResponse.ProductHeaderData.LOB ) $objBuilder | Add-Member -MemberType NoteProperty -Name 'ModelDescription' -Value ( '{0}' -f $xmlContent.AssetSummaryDTO.AssetSummaryResponse.ProductHeaderData.SystemDescription ) $objBuilder | Add-Member -MemberType NoteProperty -Name 'ShipDate' -Value ( '{0}' -f $( Get-Date -Date $xmlContent.AssetSummaryDTO.AssetSummaryResponse.AssetHeaderData.ShipDate ` -UFormat '%Y-%m-%d' ) ) # Check if system has extended or initial warranty If ( $xmlContent.AssetSummaryDTO.AssetSummaryResponse.AssetEntitlementData.AssetEntitlement.EntitlementType -contains 'EXTENDED' ) { $strWarrantyType = 'Extended' [datetime]$dtSupportEndDate = $xmlContent.AssetSummaryDTO.AssetSummaryResponse.AssetEntitlementData.AssetEntitlement | Where-Object {$_.EntitlementType -match 'EXTENDED'} | ForEach-Object {$_.EndDate} | Sort-Object -Descending | Select-Object -First 1 } Else { $strWarrantyType = 'Initial' [datetime]$dtSupportEndDate = $xmlContent.AssetSummaryDTO.AssetSummaryResponse.AssetEntitlementData.AssetEntitlement | Where-Object {$_.EntitlementType -match 'INITIAL'} | ForEach-Object {$_.EndDate} | Sort-Object -Descending | Select-Object -First 1 } $objBuilder | Add-Member -MemberType NoteProperty -Name 'WarrantyType' -Value ( '{0}' -f $strWarrantyType ) $objBuilder | Add-Member -MemberType NoteProperty -Name 'SupportEndDate' -Value ( '{0}' -f $(Get-Date -Date ($dtSupportEndDate) -UFormat '%Y-%m-%d') ) [int] $intDaysRemaining = $((New-TimeSpan -Start $(Get-Date) -End $dtSupportEndDate).Days) $objBuilder | Add-Member -MemberType NoteProperty -Name 'DaysRemaining' -Value $intDaysRemaining If ( $(New-TimeSpan -Start $(Get-Date) -End $dtSupportEndDate).Days -lt 1 ) { $strWarrantyStatus = 'Expired' } Else { $strWarrantyStatus = 'Active' } $objBuilder | Add-Member -MemberType NoteProperty -Name 'WarrantyStatus' -Value ( '{0}' -f $strWarrantyStatus ) $objReportData += $objBuilder } } $objReportData # Clean up the environment Write-Debug -Message 'Reverting local variables to snapshot' } End { } |