C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
PowerShell Out-FileThe Out-File cmdlet in PowerShell sends the output to a specific file. When you need to use its parameters, use this cmdlet instead of redirection operator (>). SyntaxOut-File [-FilePath] <string> [[-Encoding] {unknown | string | unicode | bigendianunicode | utf8 | utf7 | utf32 | ascii | default | oem}] [-Append] [-Force] [-NoClobber] [-Width <int>] [-NoNewline] [-InputObject <psobject>] [-WhatIf] [-Confirm] [<CommonParameters>] Out-File [[-Encoding] {unknown | string | unicode | bigendianunicode | utf8 | utf7 | utf32 | ascii | default |oem}] -LiteralPath <string> [-Append] [-Force] [-NoClobber] [-Width <int>] [-NoNewline] [-InputObject <psobject>] [-WhatIf] [-Confirm] [<CommonParameters>] ParametersFollowings are the parameters used in this cmdlet: -FilePath and -LiteralPath Both the parameters are used to specify the path to the file in the command. -Encoding This parameter specifies the type of character used in the file. The default value of this parameter is UTF8NoBOM. Followings are the acceptable values for this parameter:
-Append This parameter is used to add the output at the end of an existing file. -Force This parameter overwrites the existing read-only files and the read-only attributes. It does not override security restrictions. -NoClobber This parameter prevents the existing files with the same name to be overwritten and shows you a message that the file already exists. -Width This parameter specifies the number of characters in each output line. -NoNewLine This parameter specifies that the content which is written to the file does not end with a new line character. -InputObject This parameter specifies those objects which are written to the file. -WhatIf This parameter describes what would happen if the cmdlet executes. -Confirm This parameter prompts you a confirmation before executing a cmdlet. ExamplesExample 1: The command in this example sends the output of the get-childitem cmdlet to the text file whose path is specified in the command by using the -FilePath parameter. Example 2: The command in this example does not send the output of the get-process cmdlet to the k.txt file, and it shows an error because the file already exists. The file k.txt cannot be overwritten because of the -NoClobber parameter in the command.
Next TopicPowerShell Write-Host
|