title: PowerShell Script to query and delete print jobs older than "x" days
body: <p>I started putting this PowerShell Script together, the hope would be to replace some tasks that are currently carried out manually</p>
  
  <p>I'm using the</p>
  
  <pre><code>get-Date.AddDays()
  </code></pre>
  
  <p>function</p>
  
  <p>I'm using the ISE to build the script and in testing I get output if I single out the 'starttime' property, but this seems to be a catch all because the values all come up null, ideally I'd like to use the 'timesubmitted' property, but the date seems to output in an odd that I don't think is being read correctly because my queries with 'timesubmitted' always come up empty</p>
  
  <p>it comes out in this format, if you do an open query</p>
  
  <pre><code>20120416030836.778000-420
  </code></pre>
  
  <p>here's what I have so far.</p>
  
  <p>disregard the | 'format-table' function that's just so I can see if I'm getting the desired output</p>
  
  <pre><code>#Clears Old Print Jobs on Specified server
  
  #Sets Execution Policy for Script to run
  Set-ExecutionPolicy RemoteSigned -Force
  
  #establishes variable for cutoff date
  $d = Get-Date
  $old = $d.AddDays(-4)
  
  #Queries WMI and retrieves print jobs
  Get-WmiObject -class win32_printjob -namespace "root\CIMV2" | where-object {$_.timesubmitted -lt
  "$old"} | ft caption,document,jobid,jobstatus,owner,timesubmitted
  </code></pre>