Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,23 @@ To update Halo you will first need to determine which field name you are using t

update-warrantyinfo -Halo -HaloClientID "YourAPIAppClientID" -HaloClientSecret "YourHaloAPIAppSecret" -HaloURL "YourHaloURL" -HaloSerialField "Halo Serial Field Name" -SyncWithSource -OverwriteWarranty -ExcludeApple

To speed the script up we also recommend the following:

Create a Column Profile in Halo that includes just the following:

- Asset/Serial Number (inventory_number)
- Parts Warranty Start
- Parts Warranty Ends
- ProductNumber (A field required for HP Warranty checks)

Get the ID of that Column Profile and use the -columnsID switch as in the example below

update-warrantyinfo -Halo -HaloClientID "YourAPIAppClientID" -HaloClientSecret "YourHaloAPIAppSecret" -HaloURL "YourHaloURL" -HaloSerialField "Halo Serial Field Name" -SyncWithSource -OverwriteWarranty -ExcludeApple -ColumnsID "YourColumnProfileID"

By default we have disabled the ability to resume where you have left off in the case of a failure or for some other reason. You can enable this by using the -Resume switch as in the example below. This will make the script much slower to run, especially if you are not using a column profile

update-warrantyinfo -Halo -HaloClientID "YourAPIAppClientID" -HaloClientSecret "YourHaloAPIAppSecret" -HaloURL "YourHaloURL" -HaloSerialField "Halo Serial Field Name" -SyncWithSource -OverwriteWarranty -ExcludeApple -ColumnsID "YourColumnProfileID" -Resume

## BluetraitIO

To execute an update of all devices in BluetraitIO use:
Expand Down
4 changes: 2 additions & 2 deletions private/Get-HPWarranty.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
function get-HPWarranty([Parameter(Mandatory = $true)]$SourceDevice, $Client) {
function get-HPWarranty([Parameter(Mandatory = $true)]$SourceDevice, $Client, $ProductNumber) {
if ($script:ExcludeHP -ne $True) {
try {
$HPReq = Invoke-RestMethod -Uri "https://warrantyapiproxy.azurewebsites.net/api/HP?serial=$($SourceDevice)"
$HPReq = Invoke-RestMethod -Uri "https://warrantyapiproxy.azurewebsites.net/api/HP?serial=$($SourceDevice)&Product=$($ProductNumber)"
} catch {
$HPReq = $null
}
Expand Down
100 changes: 63 additions & 37 deletions private/Get-WarrantyHalo.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,78 +7,104 @@ function Get-WarrantyHalo {
[string]$HaloSerialField,
[boolean]$SyncWithSource,
[boolean]$Missingonly,
[boolean]$OverwriteWarranty
[boolean]$OverwriteWarranty,
[string]$ColumnsID,
[switch]$resume
)


write-host "Source is Halo. Grabbing all devices." -ForegroundColor Green
write-host "Source is Halo." -ForegroundColor Green
#Get the Halo API Module if not installed
if (Get-Module -ListAvailable -Name HaloAPI) {
Import-Module HaloAPI
} else {
Install-Module HaloAPI -Force
Import-Module HaloAPI
Install-Module HaloAPI -RequiredVersion 1.20.0 -Force
Import-Module HaloAPI
}

Connect-HaloAPI -URL $HaloURL -ClientId $HaloClientID -ClientSecret $HaloClientSecret -Scopes "edit:assets"

#Get Devices
$ResumeLast = test-path 'Devices.json'
If ($ResumeLast) {
write-host "Found previous run results. Starting from last object." -foregroundColor green
$Devices = get-content 'Devices.json' | convertfrom-json
$ResumeLast = Test-Path 'Devices.json'
If ($ResumeLast -and $script:resume) {
write-host "Found previous run results. Starting from last object." -ForegroundColor green
$Devices = Get-Content 'Devices.json' | ConvertFrom-Json
} elseif ($script:ColumnsID){
Write-Host "getting Halo Assets Using Columns ID $script:ColumnsID" -ForegroundColor Green
$Devices = Get-HaloAsset -ColumnsID $script:ColumnsID
} else {
write-Host "Getting All Halo Asset Information" -ForegroundColor Green
$Devices = Get-HaloAsset -FullObjects
}
}

$i = 0
$warrantyObject = foreach ($device in $Devices) {
$AssetArray = New-Object System.Collections.Generic.List[PSObject] # Initialize a generic list

foreach ($device in $Devices) {
$i++
$null = set-content 'Devices.json' -force -value ($Devices | select-object -skip $i | convertto-json -depth 5)

if ($script:resume) {
$null = Set-Content 'Devices.json' -Force -Value ($Devices | Select-Object -Skip $i | ConvertTo-Json -Depth 5)
}
# Find the Serial Number
if ($Device."$($HaloSerialField)") {
$Serial = $Device."$($HaloSerialField)"
$ProductNumber = $Device."$($ProductNumber)"
} else {
$Serial = ($Device.Fields | where-object { $_.name -eq $HaloSerialField }).value
if (($Serial | measure-object).count -ne 1) {
$Serial = ($Device.customfields | where-object { $_.name -eq $HaloSerialField }).value
if (($Serial | measure-object).count -ne 1) {
$Serial = ($Device.Fields | Where-Object { $_.name -eq $HaloSerialField }).value
if (($Serial | Measure-Object).count -ne 1) {
$Serial = ($Device.customfields | Where-Object { $_.name -eq $HaloSerialField }).value
if (($Serial | Measure-Object).count -ne 1) {
Write-Error "Serial field not found"
continue
}
}
}



Write-Progress -Activity "Grabbing Warranty information" -status "Processing $Serial. Device $i of $($devices.Count)" -percentComplete ($i / $Devices.Count * 100)
$WarState = Get-Warrantyinfo -DeviceSerial $Serial -client $device.client_name


Write-Progress -Activity "Grabbing Warranty information" -Status "Processing $Serial. Device $i of $($devices.Count)" -PercentComplete ($i / $Devices.Count * 100)
if ($ProductNumber) {
$WarState = Get-Warrantyinfo -DeviceSerial $Serial -client $device.client_name -ProductNumber $ProductNumber
} else {
$WarState = Get-Warrantyinfo -DeviceSerial $Serial -client $device.client_name
}
if ($SyncWithSource -eq $true) {

$AssetUpdate = @{
id = $Device.id
warranty_start = $WarState.StartDate
warranty_end = $WarState.EndDate
warranty_note = $WarState.'Warranty Product name'
}

switch ($OverwriteWarranty) {
$true {
if ($null -ne $warstate.EndDate) {
$null = Set-HaloAsset -Asset $AssetUpdate
}

}
$false {
if ($null -eq $Device.warranty_end -and $null -ne $warstate.EndDate) {
$null = Set-HaloAsset -Asset $AssetUpdate

$AssetArray.Add((New-Object PSObject -Property $AssetUpdate)) # Add AssetUpdate to the generic list
# If $i is a multiple of 100, set the warranties for all devices processed so far
if ($i % 100 -eq 0) {
#$AssetArrayJson = $AssetArray | ConvertTo-Json -Depth 10
$maxRetries = 3 # Set the maximum number of retries
$retryCount = 0
while ($retryCount -lt $maxRetries) {
try {
$null = Set-HaloAsset -Asset $AssetArray
$AssetArray.Clear() # Clear the list
break # Exit the loop on success
} catch {
Write-Warning "Attempt $retryCount failed. Retrying..."
$retryCount++ # Increment the retry counter
Start-Sleep -Seconds 2 # Wait for a bit before retrying (optional)
}
}

if ($retryCount -eq $maxRetries) {
Write-Error "Failed to set asset warranties after $maxRetries attempts."
}
}
}
$WarState
}
Remove-item 'devices.json' -Force -ErrorAction SilentlyContinue
return $warrantyObject

# Process any remaining warranties
if ($AssetArray.Count -gt 0) {
#$AssetArrayJson = $AssetArray | ConvertTo-Json -Depth 10
$null = Set-HaloAsset -Asset $AssetArray
}

Remove-Item 'devices.json' -Force -ErrorAction SilentlyContinue
#return $warrantyObject
}
3 changes: 2 additions & 1 deletion public/Get-WarrantyInfo.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ function Get-Warrantyinfo {
Param(
[string]$DeviceSerial,
[String]$client,
[String]$vendor
[String]$vendor,
[string]$ProductNumber
)
if ($LogActions) { add-content -path $LogFile -Value "Starting lookup for $($DeviceSerial),$($Client)" -force }
if ($vendor) {
Expand Down
8 changes: 7 additions & 1 deletion public/Update-WarrantyInfo.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,11 @@ function update-warrantyinfo {
[String]$HaloClientSecret,
[Parameter(ParameterSetName = 'Halo', Mandatory = $true)]
[String]$HaloSerialField,
[Parameter(ParameterSetName = 'Halo', Mandatory = $false)]
[String]$ColumnsID,
[Parameter(ParameterSetName = 'Halo', Mandatory = $false)]
[switch]$Resume,


[Parameter(ParameterSetName = 'Ninja', Mandatory = $true)]
[switch]$Ninja,
[Parameter(ParameterSetName = 'Ninja', Mandatory = $true)]
Expand Down Expand Up @@ -113,6 +116,9 @@ function update-warrantyinfo {
$script:ExcludeLenovo = $ExcludeLenovo
$script:ExcludeMS = $ExcludeMS
$script:LogPath = $LogFile
$script:resume = $resume
$script:ColumnsID = $ColumnsID

switch ($PSBoundParameters.Keys) {
Autotask { $WarrantyStatus = Get-WarrantyAutotask -AutotaskCredentials $AutotaskCredentials -AutotaskAPIKey $AutotaskAPIKey -SyncWithSource $SyncWithSource -MissingOnly $Missingonly -OverwriteWarranty $OverwriteWarranty | Sort-Object -Property Client }
CSV { $WarrantyStatus = Get-WarrantyCSV -Sourcefile $CSVFilePath | Sort-Object -Property Client }
Expand Down