Public/Start-RepairAudit.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 Start-RepairAudit { Set-Computers -AuditSelection $script:AuditSelection #pull from ServiceNow $count = Get-Computers | Where-object AuditStatus -eq "NotScanned" | measure $remaining = $count.Count $script:format = @{"format" = "yyyy-MM-dd HH:mm:ss" } while ($true) { Clear-Host #output list of devices remaining to be scanned Get-Computers | Where-object AuditStatus -eq "NotScanned" | Sort-Object @{expression='AuditStatus'; Descending = $True}, @{expression='ID'} | Format-Table @{Label = 'CS Number'; Expression = 'number'}, Serial, @{Label = 'Technician'; Expression = 'u_wi_primary_tech'}, @{Label = 'State'; Expression = 'state'}, @{Label = 'Substate'; Expression = 'u_substate'}, @{Label = 'Audit Status'; Expression = 'AuditStatus'} -AutoSize Write-host "IT HELPDESK REPAIR AUDIT - " $remaining " remaining `n" $scanned = Read-Host "Enter CS Number or 'exit' to complete audit" $scanned = ($scanned -replace '\s', '').ToLower() if ($scanned -ne "exit" -and $scanned -ne "" ) { $computer = Get-Computer -CS_number $scanned #checks if $scanned input matches any CS# from Computers list returns empty if not, returns with matching value if it does if ([string]::IsNullOrEmpty($computer)) { #if input scanned is not found on the list of CS# from service now #attempt to add as bad scan Add-Computers -CS_numbers @($scanned) #sends scanned data to add computer to check if in Service now or not. If not in service now gets marked bad scan } # End If else { #if found on list $computer = Get-Computer -CS_number $scanned | select -First 1 #searches list of computers for matching CS# if ($computer.AuditStatus -eq "NotScanned") { #if found and auditstaus already equals scanned Update-Computer -CS_number $scanned -Value @{"AuditStatus" = "Scanned"} #else mark device as scanned $remaining-- } # End If else { New-Computer -InputObject $computer -Duplicate #it is marked as duplicate } # End Else } # End Else } # End If elseif($scanned -ne "exit") { #if input is "" null or empty Write-Host "Value Cannot be NULL" }#end else if else { #if input equals "exit" display computer list and break out/end script Clear-Host Get-AuditReport -ReportSelection $script:AuditSelection | Format-Table ID, @{Label = 'CS Number'; Expression = 'number'}, Serial, @{Label = 'Technician'; Expression = 'u_wi_primary_tech'}, @{Label = 'State'; Expression = 'state'}, @{Label = 'Substate'; Expression = 'u_substate'}, @{Label = 'Audit Status'; Expression = 'AuditStatus'} -AutoSize #write report to console #update ticket $ticket = Get-AuditTicket $RecordData = @{ "Filter" = @(@("number", "-eq", "$ticket")); "Table" = "sc_req_item"; "First" = 1; } #set param for which ticket to update Get-ServiceNowRecord @RecordData | Update-ServiceNowRecord -Values @{description = Get-AuditReport -ReportSelection $script:AuditSelection} #upload data to ticket Update-WorkNotes -AuditSelection $script:AuditSelection #updates the work notes for all scanned repair tickets Write-Host "Duplicate or Faulty Scan data: " Get-BadScans | Format-Table ID, number, Serial, u_wi_primary_tech, state, u_substate, AuditStatus -AutoSize break } # End Else } # End While }#end Start-ReturnAudit |