PoshCode Logo PowerShell Code Repository

print-file by karl prosser 5 years ago
embed code: <script type="text/javascript" src="http://PoshCode.org/embed/843"></script>download | new post

simple V1 function to print files, either listed, or through the pipeline. No error checking implemented

  1. function print-file($file)
  2. {
  3.  begin  {              
  4.     function internal-printfile($thefile)
  5.     {    
  6.         if ($thefile -is [string]) {$filename = $thefile }
  7.         else {
  8.                 if ($thefile.FullName -is [string] ) { $filename = $THEfile.FullName }
  9.              }  
  10.         $start = new-object System.Diagnostics.ProcessStartInfo $filename
  11.         $start.Verb = "print"
  12.         [System.Diagnostics.Process]::Start($start)                    
  13.     }
  14.    
  15. if ($file -ne $null) {
  16.                 $filespecified = $true;
  17.                 internal-printfile $file
  18.             }
  19.        }    
  20. process{if (!$filespecified) { write-Host process ; internal-printfile $_ } }
  21.  
  22. }

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