evilknievel
Goto Top

Dell Garantie Abfrage per PowerShell Script

Hallo,

ich habe ein PowerShell Script gesucht das mir die Dell Garantie vom DellWebservice abfragt.
Habe auch eins gefunden nur bekomme ich beim Ausführen einen Fehler mit dem ich nichts Anfangen kann.
Evl. kann mir hier jemand einen Tipp geben.

Das Script kann man mit 4 Varianten Ausführen:

A) Get warranty information by service tag
.\DellWarrantyInformation.ps1 -ServiceTag 6FK2YY1

B) Get warranty information by computer name
.\DellWarrantyInformation.ps1 -ComputerName <your_computer_name>

C) Get warranty information from a text file with service tags
.\DellWarrantyInformation.ps1 -ImportFile E:\DellWarranty\ServiceTags.txt

D) Export the warranty information to a CSV file
.\DellWarrantyInformation.ps1 -ImportFile E:\DellWarranty\ServiceTags.txt -ExportCSV

Hier das Script:

[CmdletBinding()]
param(
[parameter(Mandatory=$false)]
[string]$ServiceTag,
[parameter(Mandatory=$false)]
[string]$ComputerName,
[parameter(Mandatory=$false)]
[switch]$ExportCSV,
[parameter(Mandatory=$false)]
[string]$ImportFile
)

function Get-DellWarrantyInfo {
[CmdletBinding()]
param(
[Parameter(Mandatory=$False,Position=0,ValueFromPipeline=$True,ValueFromPipelineByPropertyName=$True)]
[alias("SerialNumber")]
[string[]]$GetServiceTag
)
Process {
if ($ServiceTag) {
if ($ServiceTag.Length -ne 7) {
Write-Warning "The specified service tag wasn't entered correctly"
break
}
}
$WebProxy = New-WebServiceProxy -Uri "http://xserv.dell.com/services/AssetService.asmx?WSDL" -UseDefaultCredential
$WebProxy.Url = "http://xserv.dell.com/services/AssetService.asmx"
$WarrantyInformation = $WebProxy.GetAssetInformation(([guid]::NewGuid()).Guid, "Dell Warranty", $GetServiceTag)
$WarrantyInformation | Select-Object -ExpandProperty Entitlements
return $WarrantyInformation
}
}

if ($ServiceTag) {
if (($ComputerName) -OR ($ExportCSV) -OR ($ImportFile)) {
Write-Warning "You can't combine the ServiceTag parameter with other parameters"
}
else {
$WarrantyObject = Get-DellWarrantyInfo -GetServiceTag $ServiceTag | Select-Object @{Label="ServiceTag";Expression={$ServiceTag}},@{label="StartDate";Expression={$_.StartDate.ToString().SubString(0,10)}},@{label="EndDate";Expression={$_.EndDate.ToString().SubString(0,10)}},DaysLeft,EntitlementType
$WarrantyObject[0,1] #Remove [0,1] to get everything
}
}

if ($ComputerName) {
if (($ServiceTag) -OR ($ExportCSV) -OR ($ImportFile)) {
Write-Warning "You can't combine the ComputerName parameter with other parameters"
}
else {
[string]$SerialNumber = (Get-WmiObject -Namespace "root\cimv2" -Class Win32_SystemEnclosure -ComputerName $ComputerName).SerialNumber
$WarrantyObject = Get-DellWarrantyInfo -GetServiceTag $SerialNumber | Select-Object @{Label="ComputerName";Expression={$ComputerName}},@{label="StartDate";Expression={$_.StartDate.ToString().SubString(0,10)}},@{label="EndDate";Expression={$_.EndDate.ToString().SubString(0,10)}},DaysLeft,EntitlementType
$WarrantyObject[0,1] #Remove [0,1] to get everything
}
}

if (($ImportFile)) {
if (($ServiceTag) -OR ($ComputerName)) {
Write-Warning "You can't combine the ImportFile parameter with ServiceTag or ComputerName"
}
else {
if (!(Test-Path -Path $ImportFile)) {
Write-Warning "File not found"
break
}
elseif (!$ImportFile.EndsWith(".txt")) {
Write-Warning "You can only specify a .txt file"
break
}
else {
if (!$ExportCSV) {
$GetServiceTagFromFile = Get-Content -Path $ImportFile
foreach ($ServiceTags in $GetServiceTagFromFile) {
$WarrantyObject = Get-DellWarrantyInfo -GetServiceTag $ServiceTags | Select-Object @{Label="ServiceTag";Expression={$ServiceTags}},@{label="StartDate";Expression={$_.StartDate.ToString().SubString(0,10)}},@{label="EndDate";Expression={$_.EndDate.ToString().SubString(0,10)}},DaysLeft,EntitlementType
$WarrantyObject[0,1] #Remove [0,1] to get everything
}
}
elseif ($ExportCSV) {
$GetServiceTagFromFile = Get-Content -Path $ImportFile
$ExportPath = Read-Host "Enter a path to export the results"
$ExportFileName = "WarrantyInfo.csv"
foreach ($ServiceTags in $GetServiceTagFromFile) {
$WarrantyObject = Get-DellWarrantyInfo -GetServiceTag $ServiceTags | Select-Object @{Label="ServiceTag";Expression={$ServiceTags}},@{label="StartDate";Expression={$_.StartDate.ToString().SubString(0,10)}},@{label="EndDate";Expression={$_.EndDate.ToString().SubString(0,10)}},DaysLeft,EntitlementType
if (!(Test-Path -Path $ExportPath)) {
Write-Warning "Path not found"
break
}
else {
$FullExportPath = Join-Path -Path $ExportPath -ChildPath $ExportFileName
$WarrantyObject[0,1] | Export-Csv -Path $FullExportPath -Delimiter "," -NoTypeInformation -Append #Remove [0,1] to get everything
}
}
(Get-Content $FullExportPath) | ForEach-Object { $_ -replace '"', "" } | Out-File $FullExportPath
Write-Output "File successfully exported to $FullExportPath"
}
}
}
}


Hier der Fehler:

New-WebServiceProxy : Die zugrunde liegende Verbindung wurde geschlossen: Unbekannter Fehler beim Empfangen..
In D:\DellWarranty\DellWarrantyInformation.ps1:27 Zeichen:17

back-to-top... $WebProxy = New-WebServiceProxy -Uri "http://xserv.dell.com/services/ ...

back-to-top~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

+ CategoryInfo : ObjectNotFound: (http://xserv.de...rvice.asmx?WSDL:Uri) [New-WebServiceProxy], WebExcept
ion
+ FullyQualifiedErrorId : WebException,Microsoft.PowerShell.Commands.NewWebServiceProxy
Die Eigenschaft "Url" wurde für dieses Objekt nicht gefunden. Vergewissern Sie sich, dass die Eigenschaft vorhanden
ist und festgelegt werden kann.
In D:\DellWarranty\DellWarrantyInformation.ps1:28 Zeichen:5

back-to-top$WebProxy.Url = "http://xserv.dell.com/services/AssetService.asmx ...

back-to-top~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

+ CategoryInfo : InvalidOperation: (face-smile , RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound

Es ist nicht möglich, eine Methode für einen Ausdruck aufzurufen, der den NULL hat.
In D:\DellWarranty\DellWarrantyInformation.ps1:29 Zeichen:5

back-to-top$WarrantyInformation = $WebProxy.GetAssetInformation(([guid]::New ...

back-to-top~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

+ CategoryInfo : InvalidOperation: (face-smile , RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull

Es ist nicht möglich, einen Index auf ein NULL-Array anzuwenden.
In D:\DellWarranty\DellWarrantyInformation.ps1:41 Zeichen:9

back-to-top$WarrantyObject[0,1] #Remove [0,1] to get everything

back-to-top~~~~~~~~~~~~~~~~~~~~

+ CategoryInfo : InvalidOperation: (face-smile , RuntimeException
+ FullyQualifiedErrorId : NullArray


Mfg
Howie

Content-Key: 313733

Url: https://administrator.de/contentid/313733

Ausgedruckt am: 19.03.2024 um 04:03 Uhr

Mitglied: Pjordorf
Pjordorf 27.08.2016 um 00:29:32 Uhr
Goto Top
Hallo,

Zitat von @evilknievel:
Habe auch eins gefunden nur bekomme ich beim Ausführen einen Fehler mit dem ich nichts Anfangen kann.
Dann ist Tante Google deine Freundin.

Evl. kann mir hier jemand einen Tipp geben.
4:3

Das Orakel will wissen:
Betriebssystem
Powershell Version
Restriction Policy
Wie ausgeführt
Als was ausgeführt
Vorher gibt es nur Schnee in der Kugel zu sehen....

Gruß,
Peter
Mitglied: evilknievel
evilknievel 27.08.2016 um 02:35:18 Uhr
Goto Top
Betriebssystem:
Windows 10 Pro 64bit

Powershell Version:
Name: ConsoleHost
Version: 5.0.10586.494
InstanceId: 1bceecde-2c0c-4483-bcc9-993ed9b4cd0a
UI: System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture: de-DE
CurrentUICulture : de-DE
PrivateData: Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
DebuggerEnabled: True
IsRunspacePushed: False
Runspace: System.Management.Automation.Runspaces.LocalRunspace

PSVersion 5.0.10586.494
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.10586.494
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1

Restriction Policy
Unrestricted

Wie ausgeführt
PS D:\DellWarranty> .\DellWarrantyInformation.ps1 -ServiceTag 6FK2YY1

Als was ausgeführt
PowerShell "Als Administrator gestartet"
Mitglied: colinardo
colinardo 27.08.2016 aktualisiert um 15:21:51 Uhr
Goto Top
Hallo evilknievel.
Den Webservice gibt's doch gar nicht mehr
https://gallery.technet.microsoft.com/scriptcenter/Dell-Service-Tag-21a7 ...
Kein Wunder also das du keine Verbindung mit der URL mehr aufbauen kannst (sagt schon die Fehlermeldung)..

Nutze stattdessen das neue Rest-API von Dell (Anmeldung für API-Key erforderlich).
http://en.community.dell.com/dell-groups/supportapisgroup/

Powershell kann ebenfalls problemlos mit Rest umgehen (Invoke-Restmethod).
Nachdem du dich für das API angemeldet hast kannst du (ungetestet) mit folgendem Code den Garantiestatus von mehreren Service Tags abfragen (API Key den du erhalten hast im Code eintragen):
param(
    [parameter(mandatory=$true)][ValidateNotNullOrEmpty()][string[]]$servicetags
)
$api_key = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXX'  
$result = Invoke-RestMethod -Uri "https://api.dell.com/support/assetinfo/v4/getassetwarranty/$($servicetags -join ',')?apikey=$api_key" -Method Get -ContentType 'Application/json'  
$result
.\script.ps1 -servicetags "6FK2YY1","1234567"

Grüße Uwe
Mitglied: evilknievel
evilknievel 27.08.2016 um 16:16:04 Uhr
Goto Top
Ich dank euch !
Aber des is mal wieder Typisch der Eintrag stammte aus mitte 2015 ! face-sad Naja knapp daneben ist auch vorbei !

Merci gleich mal probieren.

Grüße Howie
Mitglied: colinardo
Lösung colinardo 11.09.2016 um 18:14:15 Uhr
Goto Top
Wenns das dann war, den Beitrag bitte noch auf gelöst setzen. Merci.