Skip to content

Commit

Permalink
Update Run-PrinterDiagnostics.ps1
Browse files Browse the repository at this point in the history
Modified check for invoking user vs. active session user.  Changed version number to 1.0.2
  • Loading branch information
djust270 authored Jan 6, 2022
1 parent a58a79a commit f17124f
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions Run-PrinterDiagnostics.ps1
Original file line number Diff line number Diff line change
@@ -1,33 +1,35 @@
<#
<#
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2021 v5.8.195
Created on: 1/5/2022 8:55 AM
Created by: David Just
Filename: Run-PrinterDiagnostics
Version: 1.0
Version: 1.0.2
===========================================================================
.DESCRIPTION
Utility for basic printer diagnostics and troubleshooting
#>
####### Variables ##########
$PrintServiceLog = Get-WinEvent -Listlog "Microsoft-Windows-PrintService/Operational"
$printers=Get-Printer | Where-Object {$_.name -notlike "*Microsoft*" -and $_.name -notlike "*Fax*" -and $_.name -notlike "*OneNote*"}
$currentUser=whoami
$printers = Get-Printer | Where-Object { $_.name -notlike "*Microsoft*" -and $_.name -notlike "*Fax*" -and $_.name -notlike "*OneNote*" }
$activeUser = (((quser | select-string 'active') -split ' ').replace('>', ''))[0]
$currentUser = whoami
$currentUser = ($currentUser -split '\\')[1]
############################

###### Functions ##########

function Welcome
{

Write-Host "####################################################################################################"
Write-Host "Run-PrintDiagNostics Version 1.0`nAuthor: David Just" -ForegroundColor DarkCyan -BackgroundColor Black
Write-Host "Welcome to the Printer Diagnostics Utility `nWhere we try to make printers slightly less painful! `nCurrently Running as $($env:USERNAME)" -ForegroundColor Green -BackgroundColor Black
Write-Host "Welcome to the Printer Diagnostics Utility `nWhere we try to make printers slightly less painful! `nCurrently Running as $($currentUser.toUpper())" -ForegroundColor Green -BackgroundColor Black
Write-Host "#################################################################################################### `r"
if ($currentUser -like "*System*" -or $currentUser -like "*admin*")
if (($activeUser -ne $currentUser))
{
Write-Warning "Caution, you are currently running as $($currentUser).`nYou must run this tool as the logged on user in order to work with shared printers`nRunning as SYSTEM or another user will only show system wide printers!"
Write-Warning "Caution, you are currently running as $($currentUser.toUpper()).`nYou must run this tool as the logged on user in order to work with shared printers`nRunning as SYSTEM or another user will only show system wide printers!"
}

}
Expand Down Expand Up @@ -71,7 +73,7 @@ $log=Get-WinEvent -ListLog 'Microsoft-Windows-PrintService/Operational';$log.IsE

}

function RestartSpooler #Clears and restarts print spooler service.
function RestartSpooler #Clears and restarts print spooler service.
{
Write-Host "Restarting Print Spooler..." -ForegroundColor White -BackgroundColor Black
$scriptblock = @'
Expand Down Expand Up @@ -105,14 +107,14 @@ Get-Service Spooler | Stop-Service ; cmd /c "del %systemroot%\System32\spool\pri

function PrintTestPage
{

$index = 1
foreach ($printer in $printers)
{

Write-Host "[$index] $($printer.name)"
$index++

}

$Selection = Read-Host "Select which printer to send a test page to"
Expand Down Expand Up @@ -146,8 +148,9 @@ function OpenPrinterCP

function MainMenu
{
$log=Get-WinEvent -Listlog "Microsoft-Windows-PrintService/Operational" | select -ExpandProperty IsEnabled
if($log){$status='Enabled'}else{$status='Disabled'}
$log = Get-WinEvent -Listlog "Microsoft-Windows-PrintService/Operational" | select -ExpandProperty IsEnabled
if ($log) { $status = 'Enabled' }
else { $status = 'Disabled' }
Write-Host "Printer Service Log Status: $($status)" -Foregroundcolor DarkCyan -BackGroundColor Black
Write-Host "Installed Printers:"
$printers | select Name, Portname, Drivername | Format-Table -AutoSize
Expand All @@ -160,7 +163,7 @@ function MainMenu
2{ RestartSpooler } #Restart and Clear Spooler
3{ cmd /c "C:\Windows\System32\rundll32.exe PRINTUI.DLL, PrintUIEntry /im" } #Add a new printer
4{ OpenPrinterCP }
5{ PrintTestPage}
5{ PrintTestPage }
6{ Write-Host "Thank you for using the Print Diagnostic Tool. Happy Printing!"; sleep 2; break } #Quit
}

Expand All @@ -170,5 +173,3 @@ function MainMenu
Welcome
sleep 1
MainMenu


0 comments on commit f17124f

Please sign in to comment.