Public/Update-Asset.ps1
<#PSScriptInfo
.VERSION 1.0 .GUID 972a6d04-f905-4347-98b1-6bf00d8ce204 .AUTHOR dmcanady .COMPANYNAME .COPYRIGHT .TAGS .LICENSEURI .PROJECTURI .ICONURI .EXTERNALMODULEDEPENDENCIES .REQUIREDSCRIPTS .EXTERNALSCRIPTDEPENDENCIES .RELEASENOTES .PRIVATEDATA #> function Update-Asset { Write-Host "Updating Asset Inventory Date" #creates list called $Assets whcih contains the devices from the audit marked "Scanned" $Assets = $script:Computers | Where-object AuditStatus -eq "Scanned" #variable needed for progress bar $indexvar = 0; foreach ($asset in $Assets) { #sets variables for sys_id and time/ could be removed but makes for easier reading/editing $sysid = $asset.sys_id $device = $asset.display_name $currentTime = Get-Date -Format "yyyy-MM-dd HH:mm:ss" $AssetData = @{ 'Table' = "alm_hardware" 'SysId' = "$sysid" 'Values' = @{ #'comments' = ""; #sets the comments box 'u_last_physical_inventory_date' = "$currentTime"; #'CustomFields' = @{ #'u_last_physical_inventory_date' = "$currentTime" #} } } #set param for which ticket to update # make progress bar to show status $indexvar = $indexvar + 1 $percent = (($indexvar/$Assets.count)*100) Write-Progress -Activity "Updating Physical Hardware Inventory Date for: $device" -PercentComplete $percent Update-ServiceNowRecord @AssetData #pushes update to servicenow } Write-Host "Finished Updating Asset Inventory Date" } |