Jump to content

Asset Management: Update Warranty expires date

Giuseppe Iannacone

Recommended Posts

I was trying to update the expires date with the powershell module for hornbill, I've modified a script suggested in a post by @samwoo for disposal, but unfortunately it doesn't work.
Can someone help me in understanding why?

Script example

# Import Hornbill XMLMC Powershell Module
Import-Module D:\Asset_Hornbill\powershell\xmlmcModule.psm1

# Import from CSV file, the Asset Name column should be called - "Name" - or it can be changed in the script below
$pathToCSV = "[Path for csv file].csv"
$warrantyAssets = Import-Csv -path $pathToCSV

foreach($asset in $warrantyAssets)
  # Get the Asset Name from the name column in the CSV
  $assetName = "$asset.name"
  $date = (get-date("2015-07-15 00:00:00")).toString("yyyy-MM-dd hh:mm:ss")
  write-host $assetName
  write-host $date

  # Define instance connection details & API key for session authentication
  $hbInstance ="instancename"
  $hbZone     = "eur"
  $hbAPIKey   = "APIkey"
  Set-Instance -Instance $hbInstance  -Key $hbAPIKey -Zone $hbZone

  # Build the API call to return the machines where the asset number matches in Hornbill
  Add-Param       "application"   "com.hornbill.servicemanager"
  Add-Param       "entity"        "Asset"

  Open-Element    "searchFilter"
    Add-Param       "column"    "h_name"
    Add-Param       "value"     $assetName
  Close-Element   "searchFilter"

  # Invoke XMLMC call, output returned as PSObject
  $hornbillAssetOutput = Invoke-XMLMC "data" "entityBrowseRecords2"
  # Convert the results of the API results into a workable format
  $hornbillAsset = $hornbillAssetOutput.Params.rowData.row

  # Update the Assets accordingly to warranty
  Add-Param       "application" "com.hornbill.servicemanager"
  Add-Param       "entity" "Asset"

  Open-Element    "primaryEntityData"

    Open-Element    "record"

      # Update the Asset matching the Name
      Add-Param       "h_name" $assetName

      # Set the Warranty expiration date
      Add-Param       "h_warranty_expires" $date
    Close-Element "record"

  Close-Element   "primaryEntityData"

  # Invoke XMLMC call, output returned as PSObject
  $xmlmcAssetUpdate = Invoke-XMLMC "data" "entityUpdateRecord"

# Important! Remove XMLMC module from memory for security once XMLMC calls complete
Remove-Module xmlmcModule


Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...