Public/Set-AuditTicket.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 Set-AuditTicket {
    param(
        [parameter(Mandatory, HelpMessage = "Accepted Tickets are: TKTXXXXXXX")]
        [ValidatePattern("[T][K][T][0-9][0-9][0-9][0-9][0-9][0-9][0-9]")]
        [string]$Ticket,
        [string]$AuditSelection
    )

    #checks if ticket entered is a Helpdesk Assignment Audit ticket that matches office provided
    $RecordData = @{
        "Filter"     = @(@("number", "-eq", "$ticket"));
        "Table"      = "sc_req_item";
        "First"      = 1;
        "Properties" = @("short_description");
    } #set param for which ticket to update

    #attempts to pull the provided ticket from servicenow
    $AuditTicketRecord = Get-ServiceNowRecord @RecordData 

    #switch statement for office abbreviations
    $OfficeAbbr = switch ($script:Office.name) {
        "Demoss" { "DH" }
        "Green" { "GH" }
        "LUCOM" { "LUCOM" }
    }

    #checks the description and matches it against provided audit type
    if ($AuditTicketRecord.short_description -eq ($OfficeAbbr + " HDCS " + $AuditSelection + " Audit"))
    {
        Write-Host "Ticket Accepted"
        $script:AuditTicket = $ticket #sets AssignmentAuditTicket for future use
    }
    else {
        throw "Wrong Ticket idiot"
    }
}