PowerShell Logo Small

Out-File



This is the built-in help made by Microsoft for the command 'Out-File', in PowerShell version 2 - as retrieved from Windows version 'Microsoft® Windows Vista™ Ultimate ' 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] <string>] [-Append] [-Force] [-InputObject <psobject>] [-NoClobber] [-Width <int>] [-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/?LinkID=113363
Out-String
Out-Null
Out-Host
Out-Printer
Out-Default
Tee-Object

REMARKS

<

Examples


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

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



Description
-----------
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 --------------------------

C:\PS>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



Description
-----------
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 be
ing overwritten. The output shows the error message that appears when NoClobber is used with an existing file.








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

C:\PS>$a = get-process

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



Description
-----------
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 se
arch 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 cha
racters, the rightmost column in the process table is omitted.








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

C:\PS>set-location hklm:\software

c:\PS>get-acl mycompany\mykey | out-file -filepath c:\ps\acl.txt

c:\PS>get-acl mycompany\mykey | out-file -filepath filesystem::acl.txt



Description
-----------
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 demonst
rate these methods.