title: How to Add Date/Time to Each Line before exporting to CSV
body: <p>I've got a nice working powershell function called PSO.
  The PSO function searches for one or more specific windows processes based on the given input/parameter. When a procesname matches the searchparameter it exports/appends the process owner and more info to a csv file. All good so far.</p>
  
  <p>Now I really like to add date and time info to each line PowerShell writes to the csv. I've been struggling with it for a while now. I've got somehting simular working in VBScript, but i'm really starting to like powershell and like to see and learn more.</p>
  
  <p>Below The PSO Function, I assume this is the area where Date and Time should be generated and added... right?</p>
  
  <pre><code>Function Get-PSO($searchString)
  # http://powershell.com/cs/blogs/tips/archive/2009/12/17/get-process-owners.aspx
  # Usage: Get-PSO * OR Get-PSO exp*,*paint*,calc*,notepad*
  # Sample Export2csv: Get-PSO notepad* | Export-CSV $env:userprofile\desktop\export.csv -Append 
  
  # A few date/time formats for later use... i hope
  $date=(Get-Date -format "yyyy-MM-d")
  $time=(Get-Date -format "HH:mm:ss")
  $datetime=(Get-Date -format "yyyy-MM-d HH:mm")
  
  $foundProcess = ps $searchString -ea silentlycontinue
  if($foundProcess -eq $null) { return; }
  $foundprocess | % {
  gwmi Win32_Process -Filter ("Handle={0}" -f $_.id ) | 
   % { Add-Member -TypeName Type -InputObject $_ -MemberType NoteProperty -Name Owner -Value ($_.GetOwner().User) -PassThru } |
  # See below my last attempt to get this tot work
  # % { Add-Member -TypeName Type -InputObject $_ -MemberType NoteProperty -Name Owner -Value ($_.GetOwner().User) -MemberType NoteProperty -Name Date -Value $date -PassThru } |
    select Name, Handle, Owner, Type
  }
  </code></pre>
  
  <p>When I run the function ; Get-PSO notepad* | Export-CSV $env:userprofile\desktop\export.csv -Append) I get the following result:</p>
  
  <p>Name;Handle;Owner;Type</p>
  
  <p>notepad++.exe;7736;Dave;</p>
  
  <p>I like to Add Date/Time and the result should look something like:</p>
  
  <p>Name;Handle;Owner;Date;Time;DateTime;Type</p>
  
  <p>notepad++.exe;7736;Dave;5-4-2015;20:07;5-4-2015 20:07;</p>
  
  <p>Anyone? some help or ideas would be very much appreciated.</p>