Public/Update-WorkNotes.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-WorkNotes {
    param (
        [string]$AuditSelection
    )

    Write-Host "Updating Ticket Work Notes"
    
    if ($AuditSelection -eq "Repair")
    {
        $message = "Daily Repair"
    }
    elseif ($AuditSelection -eq "Assignment")
    {
        $message = "Weekly Assignment"
    }
    
  
    #Selects the computers that were scanned
    $Assets = $script:Computers | Where-object AuditStatus -eq "Scanned"

    $indexvar = 0;

    foreach ($asset in $Assets) { 
        #sets variables for sys_id and time/ could be removed but makes for easier reading/editing
        $CS_number = $asset.number
        #$currentTime = Get-Date -Format "yyyy-MM-dd HH:mm:ss"

        $RecordData = @{
            "Filter"     = @(@("number", "-eq", "$CS_number"));
            "Table"      = "u_computer_support";
            "First"      = 1;
        } #set param for which ticket to update

        $UpdateInfo = @{
            'Table' = "u_computer_support"
            'Values' = @{
                #'comments' = ""; #sets the comments box
                'work_notes' = "This device was verified to be at " + $script:Office.Name + " on the $message Audit."; #sets the comments box
                #'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 Work Notes for $CS_number" -PercentComplete $percent

        #retrieve the CS ticket and post comment
        Get-ServiceNowRecord @RecordData  | Update-ServiceNowRecord @UpdateInfo


    }

    Write-Host "Finished Updating Ticket Work Notes"
}