Sean's Personal Code Samples And References
Out-File

Send output to a file. When you wish to specify parameters, use Out-File instead of the redirection operator (>).

Syntax
      Out-File [-filePath] string [[-encoding] string]
            [-append] [-width int] [-inputObject psobject]
               [-force] [-noClobber] [-whatIf]
                  [-confirm] [CommonParameters]
Key
   -filePath path
       The path to the output file. 
   
   -encoding string
       The character encoding used in the file. 
       "Unicode", "UTF7", "UTF8", "UTF32", "ASCII", "BigEndianUnicode",
       "Default", or "OEM". The default is Unicode.
       Default=system ANSI code page. 
       OEM=OEM code page identifier for the OS.

   -append 
       Add the output to the end of an existing file, instead of replacing 
       the file contents.

   -width int
       The number of characters in each line of output. Any additional
       characters are truncated, not wrapped. If you omit this parameter, 
       the width is determined by the characteristics of the host. The default 
       for the PowerShell.exe host is 80 (characters).

   -inputObject psobject
       The object to be written to file. {may be piped}
       A command, expression or variabale that contains the objects.
	   
   -force 
       Override restrictions that prevent the command from succeeding, apart
       from security settings. e.g. Force will create file path directories 
       or override a files read-only attribute, but will not change file permissions.
        
   -noClobber 
       Do not overwrite (replace the contents) of an existing file. 
       By default Out-File will overwrite an existing file without warning.
       If both -Append and -NoClobber are specified, the output is appended.
        
   -whatIf
       Describe what would happen if you executed the command without
       actually executing the command.
        
   -confirm
       Prompt for confirmation before executing the command.
		
   CommonParameters:
       -Verbose, -Debug, -ErrorAction, -ErrorVariable, -WarningAction, -WarningVariable,
       -OutBuffer -OutVariable.
If the current location is a registry key, then -filepath must either be specified as filesystem::yourfilename.txt or use a full path C:\docs\yourfile.txt

The final part of displaying output is a hidden background call to an Output cmdlet, by default as the last part of the execution process PowerShell calls the default output cmdlet which is typically Out-Host.

Examples

Send a list of processes to process.txt:

PS C:\> get-process | out-file -filepath C:\docs\process.txt
PS C:\> get-process | out-file C:\docs\process.txt

The same thing, but storing the list of processes in a variable first and truncating the output at 50 characters:

PS C:\> $a = get-process
out-file -filepath C:\docs\process.txt -inputobject $a -width 50

Save a registry key to file :

PS C:\> set-location hklm:\software
PS HKLM:\software> get-acl ODBC | out-file c:\docs\acl.txt -width 200
Sean Marcellus
There are 10 kinds of people e in this world, those who understand binary and those who don’t.