PowerShell Project Final


PowerShell Project
The print spooler is a service application that manages printer jobs sent from a computer to printer or print server, allowing for a buffer - though more commonly known as a queue. The print queue as described, is a queue of stored printing tasks that execute in chronological order, allowing for fair use and management of printer resources. While there are various reasons a host may receive errors pertaining to print spooler communication, I have decided to write a PowerShell script to run a series of commonly used administrative tasks that simply restarts the service as quick fix script, as it is a common occurrence in my current Administrative role. It is recommended that if the problem persists, further investigation will be required.
To perform this task using the Windows GUI, an Administrator would;
Windows Key + R and type services.msc
Once ran will bring up the Services dialog as seen below. At this point we look for “Print Spooler”, right click where we can then stop start or restart the service.
The Script
# The purpose of this script is restart the print spooler after detecting whether or not it is running.
$ServiceName = 'spooler'
$arrService = Get-Service -Name $ServiceName
write-host "
            _       _            
           (_)     | |          
 _ __  _ __ _ _ __ | |_
| '_ \| '__| | '_ \| __|
| |_) | |  | | | | | |_  
| .__/|_|  |_|_| |_|\__|
| |     Spool3r KiLLa 5000 v2-_                    
|_|   _- jimdotdev@gmail.com -_
"
start-sleep -s 2 # time delays
write-host ""
write-host "Checking current spooler status"
start-sleep -s 2
write-host ""
if ($arrService.Status -ne 'Running') # checks the current spooler status and see if it is not equivalent to "Running" if it is, it attempts to start it
{                                     # if it is not, it moves on to elseif
    write-host ""
    write-host "It Looks like the printer spooler is not running"
    write-host ""
    start-sleep -s 2
    write-host "Attempting to start Print Spooler"
    write-host ""
    Start-Service $ServiceName
    Start-Sleep -seconds 5
    $arrService.Refresh()
    if ($arrService.Status -eq 'Running')
    {
        Write-Host " The Print Spooler is now Running"
    }
   
}
elseif ($arrService.Status -eq 'Running') #Checks to see if the printer is equivlant to "running" and if is, stops and restarts it to restart the spooler
    {
    write-host " The Print Spooler is already running"
    start-sleep -s 2
    write-host ""
    write-host "Attempting to stop the Print Spooler..."
    write-host ""
    Stop-Service $ServiceName -force
    start-sleep -s 2
    write-host " Now attempting to restart the Print Spooler..."
    Start-service $ServiceName
    start-sleep -s 2
    $arrService.Refresh() #refreshes the request to recheck status
    if ($arrService.Status -eq 'Running')#Makes sure the print spool is in fact running again
    {
        write-host ""
        Write-Host "The Print Spooler has been restarted and is currently running"
        Start-sleep -s 2
        }
        }
    if ($arrService.Status -eq 'Running') # if the print spooler is running, should we print a test page?
    {
    write-host ""
        $answer = Read-Host "Should we attempt to print a test page? Yes/No" #Read-host waits for response from host then uses if statements based on option
        if ($answer -eq "yes" -or $answer -eq "y")
        {
        write-host ""
        "This is a test page generated by the Print Spool3r KiLLa 5000 v2 written by jimdotdev. Jim is a Network Administrator & Ethical Hacker providing diversity through a wide
        arrange of skillsets. To learn more, you can visit his blog  @                    
  (_|_)             | |     | |    | |                    
   _ _ _ __ ___   __| | ___ | |_ __| | _____   _____ __ _
  | | | '_ ` _ \ / _` |/ _ \| __/ _` |/ _ \ \ / / __/ _` |
  | | | | | | | | (_| | (_) | || (_| |  __/\ V / (_| (_| |    
  | |_|_| |_| |_|\__,_|\___/ \__\__,_|\___| \_(_)___\__,_|
  / |                                                    
|__/    jimdotdev.ca | jimdotdev@gmail.com
" | Out-Printer # this is the text being piped to the out-printer which will be what is seen as a test page
        write-host "A test page has been attempted"
         
    }
    if ($answer -eq "no" -or $answer -eq "n")
    {
    start-sleep -s 2
    write-host ""
    write-host "No test page will be printed and the script will now self terminate"
    exit
    }
    }

General Process Flow Of Script
For my current administrative role, this script is convenient as it requires little interaction with the host. Once the script is ran, the service will restart which normally fixes print spooler issues.
Expanding further:
In version 1 of this script, I was backing up the printer spooler folder to another location on the drive. I removed this function as I believed it to be unnecessary as I don't feel the spooler documentation to be critical data. To expand on it more, I would re-add this feature as an unnecessary precaution.
Remote execution: An additional feature would be remote execution of the script so an administrator could easily restart the print spooler on remote hosts with in the organization.
I plan on elaborating on this script some more to further develop my powershell scripting skills, while evaluating other tasks that can be performed as they arise. "

 ---------------------------------------------------------------------------------------------------------------------------------

Following up with some insight on this project, I was very happy to turn it in. During my time at triOS College I looked forward to learning Powershell, and while I wish we could have dedicated more time to it; I really enjoyed the lessons and was proud to have turned this in.

I now utilize powershell to execute repetitive tasks and where acquired data outputs are beneficial to have 

No comments:

Post a Comment

Professional Skills

Troubleshooting
Hardware
Networking
Security

My Experience

  • __

  • 2016 - Present

    IT/HSE Coordinator

    • Providing effective troubleshooting solutions involving printers, desktops and mobile devices - maintaining connectivity, end user satisfaction and functionality
    • Composing various documentation providing training in I.T, HSE and standard operating procedures as to ISO 9001:2015 standardization
  • 2018 - 2019

    Network Administrator Diploma, triOS College

  • 2008 - Present (.part time)

    IT Support Specialist

    • Build and support specialized workstations and gaming pc’s, providing cost effective solutions based on customers expectations and requirements
    • Provide on-site, remote and similar managed services through Windows RDS, Quick Assist and TightVNC with secured tunneling
  • __

  • 2012 - 2016

    Technical Advisor

    • Research, design and prototype various engineered specifications utilizing additive manufacturing to iterate design concepts, potential flaws and plausibility
    • Troubleshoot PLC’s, maintaining and developing various process controls with pneumatic and hydraulic circuits
  • 2011 - 2012

    Demanufacturing Technician

    • Provide technical documentation on the identification, safety precautions and dismantling procedures of desktops, servers, monitors and televisions
    • Identify and categorize desktops, server and networking equipment for potential resale
  • 2006-2011

    IT Support Specialist

    • Compiled prospects of our search engine optimization to restore and maintain online presence resulting in streamlined control and analysis of our ranking,
    • Install horizontal runs providing clean and structuralized cable management
    • Perform scheduled backups creating archival storage of sensitive data