Public/Set-AuditType.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-AuditType 
{
    write-host "`n"
    
    #prompt user for audit selection
    do {
        try { 
            [ValidatePattern("[1-3]")]$AuditChoice = Read-Host "Select the Audit you would like to perform:`n`n[1] Repair Audit `n[2] Assignment Audit `n[3] Storage Audit `n>>"
            $script:AuditSelection = switch ($AuditChoice) 
            {#Translate choice to name
                "1" {"Repair"}
                "2" {"Assignment"}
                "3" {"Storage"}
            }
        }
        catch {} #if user enters anything other than 1-3 it loops and reprompts
    } until ($?) # $? is a automatic variable that checks the status of the last attempted command. (entering valid audit type). Once completed successfully it updates to true and breaks out of loop

    Clear-Host
    while ($true){ #Prompts for User credentails and Audit Ticket number
        $AuditTicketNumber = Read-Host "Enter in the" $script:Office.Name $script:AuditSelection "TKT Number `n>>"
        try {
            New-ServiceNowSession -Url $script:URL -Credential (Get-Credential)#$script:User
        }
        catch {
            Clear-Host
            Write-Host "Unable to establish connection. Potentially incorrect credentials. Try Again:" -ForegroundColor red #won't see this
        }
        try {
            Set-AuditTicket -AuditSelection $script:AuditSelection -ticket $AuditTicketNumber #checks servicenow for Storage audit ticket matching office and number provided
            break
        }
        catch {
            Clear-Host
            Write-Host "Invalid Entry. Check Credentials and Ticket Number for correct Audit TKT Number. Try Again:" -ForegroundColor red
        }
    }#end While

    if ($script:AuditSelection -eq "Repair")
    {
        Start-RepairAudit
    }
    elseif ($script:AuditSelection -eq "Assignment")
    {
        Start-AssignmentAudit
    }
    elseif ($script:AuditSelection -eq "Storage")
    {
        Start-StorageAudit
    }
}