Zaty,
This saved me so much time. I can't thank you enough.
I altered your script slightly to pull the purchase date as well. Uploaded 1600 devices with missing information within a few hours. Would have taken me forever, now I have reliable data for planning.
Thanks again.
Code:
$assets = Invoke-Sqlcmd -ServerInstance server -Database lansweeperdb -Username lansweeperuser -Password 'password' -Query @"
SELECT a.AssetID, a.AssetName, b.Serialnumber, b.SystemSKU
FROM lansweeperdb.dbo.tblAssets a, lansweeperdb.dbo.tblAssetCustom b
WHERE a.AssetID = b.AssetID AND
a.Assettype = -1 AND
b.Warrantydate is NULL AND
b.Manufacturer in ('HP','Hewlett-Packard');
"@
foreach ($asset in $assets) {
$assetId = $asset.AssetID
$assetName = $asset.AssetName
$warranty = ((Get-HPIncWarrantyEntitlement -SerialNumber $asset.SerialNumber -ProductNumber $asset.SystemSKU).OverallEntitlementEndDate | Measure-Object -Maximum).Maximum
$StartDate = ((Get-HPIncWarrantyEntitlement -SerialNumber $asset.SerialNumber -ProductNumber $asset.SystemSKU).OverallEntitlementStartDate | Measure-Object -Minimum).Minimum
Write-Output "$assetID $assetName $warranty $StartDate"
Invoke-Sqlcmd -ServerInstance server -Database lansweeperdb -Username lansweeperuser -Password 'password' -Query @"
UPDATE dbo.tblAssetCustom
SET Warrantydate = '$warranty',PurchaseDate = '$StartDate'
WHERE assetID = $assetId
"@
}