PowerShell Logo Small

Out-File



This is the built-in help made by Microsoft for the command 'Out-File', in PowerShell version 5 - as retrieved from Windows version 'Microsoft Windows Server 2012 R2 Standard' PowerShell help files on 2016-06-23.

For PowerShell version 3 and up, where you have Update-Help, this command was run just before creating the web pages from the help files.

SYNOPSIS

Sends output to a file.

SYNTAX


Out-File [-FilePath] <String> [[-Encoding] {unknown | string | unicode | bigendianunicode | utf8 | utf7 | utf32 | ascii | default | oem}] [-Append] [-Force]
[-InformationAction {SilentlyContinue | Stop | Continue | Inquire | Ignore | Suspend}] [-InformationVariable [<System.String>]] [-InputObject [<PSObject>]] [-NoClobber]
[-Width [<Int32>]] [-Confirm] [-WhatIf] [<CommonParameters>]
Out-File [[-Encoding] {unknown | string | unicode | bigendianunicode | utf8 | utf7 | utf32 | ascii | default | oem}] [-Append] [-Force] [-InformationAction {SilentlyContinue
| Stop | Continue | Inquire | Ignore | Suspend}] [-InformationVariable [<System.String>]] [-InputObject [<PSObject>]] [-NoClobber] [-Width [<Int32>]] -LiteralPath <String>
[-Confirm] [-WhatIf] [<CommonParameters>]



Search powershellhelp.space

DESCRIPTION


The Out-File cmdlet sends output to a file. You can use this cmdlet instead of the redirection operator (>) when you need to use its parameters.



<

RELATED LINKS

Online Version: http://go.microsoft.com/fwlink/p/?linkid=293996
Out-Default
Out-Host
Out-Null
Out-Printer
Out-String
Tee-Object

REMARKS

<

Examples


-------------------------- EXAMPLE 1 --------------------------

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



This command sends a list of processes on the computer to the Process.txt file. If the file does not exist, Out-File creates it. Because the name of the FilePath parameter
is optional, you can omit it and submit the equivalent command "get-process | outfile C:\Test1\process.txt".










-------------------------- EXAMPLE 2 --------------------------

PS C:\>get-process | out-file C:\Test1\process.txt -noclobber

Out-File : File C:\Test1\process.txt already exists and NoClobber was specified.
At line:1 char:23
+ get-process | out-file <<<< process.txt -noclobber



This command also sends a list of processes to the Process.txt file, but it uses the NoClobber parameter, which prevents an existing file from being overwritten. The output
shows the error message that appears when NoClobber is used with an existing file.










-------------------------- EXAMPLE 3 --------------------------

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



These commands send a list of processes on the computer to the Process.txt file. The text is encoded in ASCII format so that it can be read by search programs like Findstr
and Grep. By default, Out-File uses Unicode format.

The first command gets the list of processes and stores them in the $a variable. The second command uses the Out-File cmdlet to send the list to the Process.txt file.

The command uses the InputObject parameter to specify that the input is in the $a variable. It uses the Encoding parameter to convert the output to ASCII format. It uses the
Width parameter to limit each line in the file to 50 characters. Because the lines of output are truncated at 50 characters, the rightmost column in the process table is
omitted.










-------------------------- EXAMPLE 4 --------------------------

PS C:\>set-location hklm:\software
PS C:\>get-acl mycompany\mykey | out-file -filepath c:\ps\acl.txt
PS C:\>get-acl mycompany\mykey | out-file -filepath filesystem::acl.txt



These commands show how to use the Out-File cmdlet when you are not in a FileSystem drive.

The first command sets the current location to the HKLM:\Software registry key.

The second and third commands have the same effect. They use the Get-Acl cmdlet to get the security descriptor of the MyKey registry subkey (HKLM\Software\MyCompany\MyKey).
A pipeline operator passes the result to the Out-File cmdlet, which sends it to the Acl.txt file.

Because Out-File is not supported by the Windows PowerShell Registry provider, you must specify either the file system drive name, such as "c:", or the name of the provider
followed by two colons, "FileSystem::", in the value of the FilePath parameter. The second and third commands demonstrate these methods.