PoshCode Logo PowerShell Code Repository

Enable-PrintHistory by KevMar 3 years ago
embed code: <script type="text/javascript" src="http://PoshCode.org/embed/5191"></script>download | new post

This enables the Microsoft-Windows-PrintService/Operational in the event log. Every time something is printed, details about the print job will be recorded into that event log.

  1. <#
  2. .Synopsis
  3.    Enables logging of print jobs
  4. .DESCRIPTION
  5.    This enables the Microsoft-Windows-PrintService/Operational in the event log. Every time something is printed, details about the print job will be recorded into that event log.
  6. .EXAMPLE
  7.    Enable-PrintHistory
  8.  
  9. #>
  10. function Enable-PrintHistory
  11. {
  12.  
  13.     [CmdletBinding()]
  14.     Param
  15.     (
  16.     )
  17.  
  18.     Begin
  19.     {
  20.     }
  21.     Process
  22.     {
  23.         Write-Verbose "Check for administrator rights"
  24.         if( ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")){
  25.            
  26.             Write-Verbose "Retreiving Microsoft-Windows-PrintService/Operational Object"
  27.             $EventLog = Get-WinEvent -ListLog Microsoft-Windows-PrintService/Operational
  28.             Write-Verbose ("Current Values: IsEnabled = {0}; MaximumSize = {1}MB; LogMode = {2}" -f $EventLog.IsEnabled,($EventLog.MaximumSizeInBytes / 1MB),$EventLog.LogMode)
  29.              
  30.             Write-Verbose "Enabling Microsoft-Windows-PrintService/Operational event log"
  31.             Write-Verbose "Setting Values: IsEnabled = True; MaximumSizeInBytes=50MB; LogMode = AutoBackup"
  32.             $EventLog |
  33.                 %{$_.IsEnabled = $true;
  34.                     $_.MaximumSizeInBytes=50MB;
  35.                     $_.LogMode = "AutoBackup"
  36.                     $_.saveChanges()}
  37.         }else{
  38.             Write-Error "This action requires administrator rights to modify the eventlog"
  39.         }
  40.  
  41.     }
  42.     End
  43.     {
  44.     }
  45. }

Submit a correction or amendment below (
click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:


Remember me