Skip to content

Protirus/PoshLenovo

Repository files navigation

PoshLenovo

Language: PowerShell Tag: Lenovo | License: MIT

GitHub contributors GitHub issues | GitHub issues-closed | PRs Welcome

powershellgallery | downloads

A PowerShell module for Lenovo API. Currently supports v2.5.


The eSupport WebAPI Documentation has also been added to the WIKI


You will need to contact either contact your 'Lenovo Account Representative' or maybe the 'Lenovo Partner Program': http://www.lenovo.com/partners/ to obtain a "ClientId".


Module Build Status

Branch AzurePipelines CI
dev Azure Build Status: Dev
master Azure Build Status: Master

Example

Setup

Need to create it's own function

$lenovoApiKeyName = "LENOVO_API_KEY"
$lenovoApiKey = "##ADD YOUR API KEY HERE##"
[Environment]::SetEnvironmentVariable($lenovoApiKeyName, $lenovoApiKey, "Machine")
$global:ApiKey = [Environment]::GetEnvironmentVariable($lenovoApiKeyName, "Machine")
#Log File Info
$LogFilePath = $PSScriptRoot
$LogFile = $LogFilePath + "\" + $MyInvocation.MyCommand.Name + "_" + (Get-Date -Format yyyy-MM-dd) + ".log"

Warranty

$Serial = "##YOUR SERIAL NUMBER##"
$warranty = Get-WarrantyBySerial -Serial $Serial
$Serials = @("#x#","#y#")
$warranties = Get-WarrantyBySerials -Serials $Serials
$WarrantyId = "#ID#"
$warranty = Get-WarrantyById -Id $WarrantyId
$WarrantyIds = @("#a#","#b#")
$warranties = Get-WarrantyByIds -Ids $WarrantyIds
$ContractId = "#ID#"
$contract = Get-ContractById -Id $ContractId
$Serial = "##YOUR SERIAL NUMBER##"
$warrantyoptions = Get-WarrantyOptionsBySerial -Serial $Serial

This will return all the Countries to get the CountryCode for a subsequent request.

$Serial = "##YOUR SERIAL NUMBER##"
$CountryCode = "GB"
$warrantyoptions = Get-WarrantyOptionsBySerialAndCountryCode -Serial $Serial -CountryCode $CountryCode

Need to work out the different Machine Types

$MachineType = "Laptop"
$warrantyoptions = Get-WarrantyOptionsByMachineType -MachineType $MachineType
$MachineType = "Laptop"
$CountryCode = "GB"
$warrantyoptions = Get-WarrantyOptionsByMachineTypeAndCountryCode -MachineType $MachineType -CountryCode $CountryCode

Catalog

$response = Get-Catalog -IncludeFutureProducts $true
$response
#$response = Get-Catalog
#$response
$response = Get-Catalog-Raw -IncludeFutureProducts $true
$response
#$response = Get-Catalog-Raw
#$response
$response = Get-Catalog-All -IncludeFutureProducts $true
$response
#$response = Get-Catalog-All
#$response
$response = Get-Catalog-Children -IncludeFutureProducts $true
$response
#$response = Get-Catalog-Children
#$response
$ProductID = "CELL-PHONES"
$response = Get-Catalog-Children -ProductID $ProductID -IncludeFutureProducts $true
$response
#$response = Get-Catalog-Children -ProductID $ProductID
#$response

Product

$Serial = "##YOUR SERIAL NUMBER##"
$response = Get-Product -Serial $Serial
$response

Content

$Id = "##ID##"
$response = Get-Content -Id $Id
$response

Support

Service Requests
$ServiceRequestId = "##ServiceRequestId##"
$Serial = "##YOUR SERIAL NUMBER##"
$response = Get-Support-ServiceRequests -ServiceRequestId $ServiceRequestId -Serial $Serial
$response
Service Orders
$Serial = "##YOUR SERIAL NUMBER##"
$response = Get-Support-ServiceOrders -Serial $Serial
$response

Part

$Id = "##ID##"
$response = Get-Part -Id "#ID#"
$response
$Ids = @("1","2")
$response = Get-PartByIds -Ids $Ids
$response

Accessory

$Id = "##ID##"
$response = Get-Accessory -Id "#ID#"
$response
$Ids = @("1","2")
$response = Get-AccessoryByIds -Id $Ids
$response
$ProductId = "##ProductId##"
$response = Get-AccessoryForProduct -ProductId "#ProductId#"
$response
$Serial = "##Serial##"
$response = Get-AccessoriesFromSerial -Serial "#Serial#"
$response

Provider

$ProductId = "##ProductId##"
$CountryCode = "##CountryCode##"
$Serial = "##Serial##"
$Coordinates = "##Coordinates##"
$response = Get-Provider-ServiceProviders -ProductId "ProductID" -CountryCode "CountryCode" -Serial "SerialNumber" -Coordinates "Coordinates"
#$response = Get-Provider-ServiceProviders -Serial "SerialNumber"
$response

Contacts

$ProductId = "##ProductId##"
$CountryCode = "##CountryCode##"
$Serial = "##Serial##"
$Coordinates = "##Coordinates##"
$response = Get-Contacts-SupportContacts
 -ProductId "ProductID" -CountryCode "CountryCode" -Serial "SerialNumber" -Coordinates "Coordinates"
#$response = Get-Contacts-SupportContacts -Serial "SerialNumber"
$response

Case

$Id = "##ID##"
$response = Get-Case -Id "#ID#"
$response
$Ids = @("1","2")
$response = Get-CasesByIds -Id $Ids
$response
$response = New-Case -Case @{}
$response

Profile Data

$type = "eSupport.Domain.Profile+Personal"
#$type = "eSupport.Domain"
$response = Get-Profile -Type $type
$response

Plain Powershell Example

Warranty

$serial = "Add you Serial Number here"
$apikey = "Add your ClientId here"

$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("ClientID", $apikey)
 
$warranty = Invoke-RestMethod http://supportapi.lenovo.com/v2.5/warranty?serial=$serial -ContentType "application/JSON" -Headers $headers
$warranty

To get your Serial number run the following in Command Prompt (PC)

WMIC BIOS GET SERIALNUMBER

Terminal (Mac)

  • system_profiler SPHardwareDataType | awk '/Serial/ {print $4}'
  • ioreg -l | awk '/IOPlatformSerialNumber/ { print $4;}'
  • system_profiler |grep "Serial Number (system)"
  • system_profiler |grep "r (system)"

Alternatives

There are also a number of scripts which post data to the above website but the API is a cleaner way to do this.

Links