ExTools-Supplemental.psm1

##################################################################################################
# Exbabylon Supplemental List of Functions
##################################################################################################



##################################################################################################
# Check-Module
# Checks to see if Module is installed on the device and installs it if it doesn't exist
##################################################################################################
Function Check-Module ([string] $ModuleToFind){
    $ModuleList = Get-Module -ListAvailable
    $ModuleExists = $false

    #Iterate through list and check if the module exists
    ForEach($Module in $ModuleList){
        If($Module.Name -eq $ModuleToFind){
            $ModuleExists = $true
        } 
    }

    #Install Mmdule if missing
    If($ModuleExists -eq $false){
        Write-Host "Module Doesn't Exist"
        Write-Host "Now Installing $ModuleToFind..."

        Try {
            Install-Module $ModuleToFind
        } Catch {
            Write-Host "Couldn't Install $ModuleToFind"
        }

    } else {
        Write-Host "$ModuleToFind exists and doesn't need to be installed"
    }
}



##################################################################################################
# Fix-PrintSpool
# Stops Print Spool service, removes the oldest print job, then starts service again
##################################################################################################
Function Fix-PrintSpool(){
    $SpoolPath = "C:\Windows\System32\spool\PRINTERS"
    
    #Turn off Print Spooler Service
    $PrintSpooler = Get-Service | Where { $_.DisplayName -eq 'Print Spooler' }
    Stop-Service $PrintSpooler
    Write-Host $PrintSpooler.DisplayName $PrintSpooler.Status
    
    #Remove the oldest print job from spool file path
    Commented Code#Dir $SpoolPath | Sort lastwritetime | Select -First 1 | Remove-Item
    
    #Turn on Print Spooler Service
    Start-Service $PrintSpooler
    Write-Host $PrintSpooler.DisplayName $PrintSpooler.Status
}

Export-ModuleMember -Function Check-Module, Fix-PrintSpool