PSLog - Send messages to a file and the screen

Version 1.1 (PSLog 1.1.zip) released on March 26, 2013Introduction There are many script snippets available to send messages to log files. However that required to explicitly call the respective log function. Another downside is that the function writing to the log does not know

PSLog 1.0.zip
 
 
 
 
 
4.8 Star
(25)
13,685 times
Add to favorites
3/26/2013
E-mail Twitter del.icio.us Digg Facebook
Sign in to ask a question


  • Write-Output
    1 Posts | Last post March 04, 2015
    • As I usually use Write-Output in place of Write-Host I've added this proxy function to the .psm1 file:
      #region Write-Output
      function Write-Output
      {
      	[CmdletBinding()]
          param (
              [Parameter(Mandatory=$true, Position=0, ValueFromPipeline=$true, ValueFromRemainingArguments=$true)]
              [AllowEmptyCollection()]
              [AllowNull()]
              [psobject[]]
              ${InputObject},
      
              [switch]
              ${NoEnumerate})
      
          begin
          {
              try {
                  ${InputObject} | ForEach-Object {
                      Write-LogEntry -EntryType Information -Message $_ -SupressConsole
                  }
                  $outBuffer = $null
                  if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer))
                  {
                      $PSBoundParameters['OutBuffer'] = 1
                  }
                  $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Write-Output', [System.Management.Automation.CommandTypes]::Cmdlet)
                  $scriptCmd = {& $wrappedCmd @PSBoundParameters }
                  $steppablePipeline = $scriptCmd.GetSteppablePipeline($myInvocation.CommandOrigin)
                  $steppablePipeline.Begin($PSCmdlet)
              } catch {
                  throw
              }
          }
      
          process
          {
              try {
                  $steppablePipeline.Process($_)
              } catch {
                  throw
              }
          }
      
          end
          {
              try {
                  $steppablePipeline.End()
              } catch {
                  throw
              }
          }
          <#
      
          .ForwardHelpTargetName Write-Output
          .ForwardHelpCategory Cmdlet
      
          #>
      }
      #endregion