Recently I attended MNSCUG meeting where Jason Sandys presented on ConfigMgr database. He showed his OSD Info Script that would write information to WMI so that you could then capture it with the hardware inventory to report back on additional information. That got me thinking about what else I'd like to have in WMI to report on... Dell Warranty Info!
Started looking for a Dell Warranty Script to get me started, found one HERE. Used that to sparks some other ideas. Contacted Dell to get the Dell Warranty API access process started. - Email here: SS-API_Support_Team@Dell.com to get the conversation started, you'll have to fill out some questionnaire, etc., but eventually, you'll get your access and own personal API Key.
I worked with my friend @Geodesicz (Mark) who is a PowerShell wizard, and he was able to build me the script I wanted. Pulls Dell Warranty Info from Dell's warranty API and places that info into WMI on the workstation. We are using a new namespace called ITLocal, which was already on the machines since we had implemented Jason Sandys OSDInfo Script the week before and decided to use that namespace for consistency.
Download Our Script HERE - Code shown below:
<#
Write Dell Warranty Information to WMI
Queries Dell Web Service API for Warranty Info
Creates Custom WMI Namespace and Class
Writes Warranty Info to WMI
Requires PowerShell V5
---------------
You can also add this custom class to be collected by Configuration Manager hardware inventory
---------------
Script written by Mark Godfrey (http://www.tekuits.com/blog) and Gary Blok (http://garytown.com/) - MN.IT
Get-DellWarranty function borrowed and modified from Craig Meinschein and Zaynab Alattar (https://github.com/pdxcat/Get-Warranty)
#>[CmdletBinding()]
Param(
[Parameter(Mandatory=$true,HelpMessage="APIKey")]
[ValidateNotNullOrEmpty()]
[string]$APIkey
)function Get-DellWarranty {
#-Added this Line blow to create Variable for local Service Tag
$ServiceTag = Get-WmiObject -Class Win32_Bios | select -ExpandProperty SerialNumber# Get a few items from WMI locally
$rawmodel = Get-WmiObject win32_computersystem | select -ExpandProperty Model
$model = "Dell " + $rawmodel
# Query Web Service API
$URL = "https://sandbox.api.dell.com/support/v2/assetinfo/warranty/tags.xml?svctags=$serviceTag&apikey=$apiKey"
$Request = Invoke-RestMethod -URI $URL -Method GET
$Warranties = $Request.getassetwarrantyresponse.getassetwarrantyresult.response.dellasset.warranties.warranty
$DELLAsset = $Request.getassetwarrantyresponse.getassetwarrantyresult.response.dellasset# Construct and write output object.
foreach($warranty in $warranties) {
$age = [datetime]::ParseExact($dellasset.shipdate,"yyyy-MM-ddTHH:mm:ss",$null)
$age = "{0:N2}" -f (([datetime]::now - $age).days / 365)
$output = New-Object -Type PSCustomObject
Add-Member -MemberType NoteProperty -Name 'ComputerName' -Value $env:COMPUTERNAME -InputObject $output
Add-Member -MemberType NoteProperty -Name 'Model' -Value $model -InputObject $output
Add-Member -MemberType NoteProperty -Name 'ServiceTag' -Value $serviceTag -InputObject $output
Add-Member -MemberType NoteProperty -Name 'Age' -Value $age -InputObject $output
# Copy properties from the XML data gotten from Dell.
foreach($property in ($warranty | Get-Member -Type Property)) {
Add-Member -MemberType NoteProperty -Name $property.name `
-Value $warranty.$($property.name) `
-InputObject $output
}
$output.StartDate = [datetime]::ParseExact($output.StartDate,"yyyy-MM-ddTHH:mm:ss",$null)
$output.EndDate = [datetime]::ParseExact($output.EndDate,"yyyy-MM-ddTHH:mm:ss",$null)
Write-Output $output
}
}$warranty = Get-DellWarranty | ? {$_.ServiceLevelDescription -ne 'DirectLine Service'}
# Set Vars for WMI Info
$Namespace = 'ITLocal'
$Class = 'Warranty_Info'
$AttributePrefix = 'WarrantyInfo_'# Does Namespace Already Exist?
Write-Verbose "Getting WMI namespace $Namespace"
$NSfilter = "Name = '$Namespace'"
$NSExist = Get-WmiObject -Namespace root -Class __namespace -Filter $NSfilter
# Namespace Does Not Exist
If($NSExist -eq $null){
Write-Verbose "$Namespace namespace does not exist. Creating new namespace . . ."
# Create Namespace
$rootNamespace = [wmiclass]'root:__namespace'
$NewNamespace = $rootNamespace.CreateInstance()
$NewNamespace.Name = $Namespace
$NewNamespace.Put()
}# Does Class Already Exist?
Write-Verbose "Getting $Class Class"
$ClassExist = Get-CimClass -Namespace root/$Namespace -ClassName $Class -ErrorAction SilentlyContinue
# Class Does Not Exist
If($ClassExist -eq $null){
Write-Verbose "$Class class does not exist. Creating new class . . ."
# Create Class
$NewClass = New-Object System.Management.ManagementClass("root\$namespace", [string]::Empty, $null)
$NewClass.name = $Class
$NewClass.Qualifiers.Add("Static",$true)
$NewClass.Properties.Add("ComputerName",[System.Management.CimType]::String, $false)
$NewClass.Properties.Add("Model",[System.Management.CimType]::String, $false)
$NewClass.Properties.Add("ServiceTag",[System.Management.CimType]::String, $false)
$NewClass.Properties.Add("ServiceLevelDescription",[System.Management.CimType]::String, $false)
$NewClass.Properties.Add("ServiceProvider",[System.Management.CimType]::String, $false)
$NewClass.Properties.Add("StartDate",[System.Management.CimType]::String, $false)
$NewClass.Properties.Add("EndDate",[System.Management.CimType]::String, $false)
$NewClass.Properties.Add("ItemNumber",[System.Management.CimType]::String, $false)
$NewClass.Properties["ItemNumber"].Qualifiers.Add("Key",$true)
$NewClass.Put()
}# Write Class Attributes
$warranty | ForEach{
$wmipath = 'root\'+$Namespace+':'+$class
$WMIInstance = ([wmiclass]$wmipath).CreateInstance()
$WMIInstance.ComputerName = $PSItem.ComputerName
$WMIInstance.Model = $PSItem.Model
$WMIInstance.ServiceTag = $PSItem.ServiceTag
$WMIInstance.ServiceLevelDescription = $PSItem.ServiceLevelDescription
$WMIInstance.ServiceProvider = $PSItem.ServiceProvider
$WMIInstance.StartDate = $PSItem.StartDate
$WMIInstance.EndDate = $PSItem.EndDate
$WMIInstance.ItemNumber = $PSItem.ItemNumber
$WMIInstance.Put()
Clear-Variable -Name WMIInstance
}
Syntax: WriteDellWarranty2WMI.ps1 -APIKey Y0UR@P1K3Y (Get your APIKey from Dell)
Make a Package & Program and push it out to your dell Computers. (remember to have Windows Manage Framework 5 already installed on your workstations).
Here is a capture of the info in WMI after the Script has been run: (Using Coretech WMI Browser)
Once in WMI, we have to add this to our Hardware Inventory:
Go into the Default Client Settings, Hardware Inventory -> Set Classes -> Add... -> Connect to WMI namespace root\ITLOCAL
Once Connected, you should see the Warranty_Info
After you check the box, and click OK, it should show up in your classes list:
I unchecked everything here, because I only want to apply this to my Dell Workstations.
I opened our Dell Client Workstation Settings (We have one that applies only to Dell Workstations, which I borrowed the idea from Mike Terrill after reading this Post about inventory bios settings.
Ok, now wait for your Hardware Inventory cycles to run and the data to populate in your ConfigMgr DB.
Ok, Building reports... Fun with SQL Report Builder!
Mark & I have created two quick and easy reports for now, just as proof of concept, but will probably find ways to pull this data into other reports as well.
- Dell Warranty Expired Report - This report shows all of the Computers in ConfigMgr that have expired Warranties:
You can click on the + next to the computer name to expand if has more than 1 warranty associated with it. - Dell Warranty Expires between dates - This report will let you pick dates and show you the computers that will expire. (If computer has more than 1 warranty, it will only use the warranty with the latest end date)
- Dell Warranty Info for specific Computer: Super simple report that lets you put in a computer name and get the info:
We created a new folder called Hardware - Warranty, and created our reports there. I've added those 3 reports to the ZIP file you can download with the Script.
Just import them into your system, as long as you kept the namespace the same as the one in our script, it should work fine. Update your Data source in each report, and you should be set.
In the 2 reports, I have it so if you click on the computer name, it links to a hardware report with more info about that specific computer. I think it's a built in ConfigMgr report, so it should still work, if not, just delete that action:
I really hope I didn't miss anything, there was a lot of parts to this. Mark will also be blogging this, since it was a joint project. He'll probably have more info about the Powershell stuff itself.
Couple of things to remember... ConfigMgr DB is NOT the same as a Configuration Management Database. When you delete the computer from ConfigMgr, there goes the data along with it. I make sure to tell our management, this data is ONLY useful for computers currently active in our system, we do NOT keep historical data.
As always, if you run into any problems, please feel free to contact me, I'll update the Blog to correct anything found. Sometimes its hard to get the proper screen captures after you've already set it up and been using it.
Also, I highly recommend checking out Jason's OSDInfo Script & Mike Terrill's Dell Posts, those might help shed some light on what we've done.