Public/Start-StorageAudit.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-StorageAudit { 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 = 'Serial'; Expression = 'serial_number'}, @{Label = 'Last Physical Inventory Date'; Expression = 'u_last_physical_inventory_date'}, @{Label = 'ServiceNow Display Name'; Expression = 'display_name'}, @{Label = 'Audit Status'; Expression = 'AuditStatus'} -AutoSize Write-host "IT HELPDESK RETURN AUDIT - " $remaining " remaining `n" $scanned = Read-Host "Enter Serial or 'exit' to complete audit" $scanned = ($scanned -replace '\s', '').ToLower() if ($scanned -ne "exit" -and $scanned -ne "" ) { $computer = Get-Computer -Serial_number $scanned #checks if $scanned input matches any serials 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 serials from service now Add-Computers -serial_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 -Serial_number $scanned | select -First 1 #searches list of computers for matching serial if ($computer.AuditStatus -eq "NotScanned") { #if found and auditstaus already equals scanned Update-Computer -Serial_number $scanned -Value @{"AuditStatus" = "Scanned"; "u_last_physical_inventory_date" = (Get-Date @script:format) } #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 = 'Serial'; Expression = 'serial_number'}, @{Label = 'Last Physical Inventory Date'; Expression = 'u_last_physical_inventory_date'}, @{Label = 'ServiceNow Display Name'; Expression = 'display_name'}, @{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-Asset #updates the last inventory date for all scanned assets Write-Host "Duplicate or Faulty Scan data: " Get-BadScans | Format-Table ID, @{Label = 'Serial'; Expression = 'serial_number'}, @{Label = 'Last Physical Inventory Date'; Expression = 'u_last_physical_inventory_date'}, @{Label = 'ServiceNow Display Name'; Expression = 'display_name'}, @{Label = 'Audit Status'; Expression = 'AuditStatus'} -AutoSize break } # End Else } # End While } #End Start-StorageAudit function |