名前 Out-File 概要 Sends output to a file. 構文 Out-File [-FilePath] [[-Encoding] {unknown | string | unicode | bigendianunicode | utf8 | utf7 | utf32 | a scii | default | oem}] [-Append] [-Force] [-InformationAction {SilentlyContinue | Stop | Continue | Inquire | Ignor e | Suspend}] [-InformationVariable []] [-InputObject []] [-NoClobber] [-Width []] [-Confirm] [-WhatIf] [] Out-File [[-Encoding] {unknown | string | unicode | bigendianunicode | utf8 | utf7 | utf32 | ascii | default | oem} ] [-Append] [-Force] [-InformationAction {SilentlyContinue | Stop | Continue | Inquire | Ignore | Suspend}] [-Infor mationVariable []] [-InputObject []] [-NoClobber] [-Width []] -LiteralPath [-Confirm] [-WhatIf] [] 説明 The Out-File cmdlet sends output to a file. You can use this cmdlet instead of the redirection operator (>) when yo u need to use its parameters. パラメーター -Append [] Adds the output to the end of an existing file, instead of replacing the file contents. 必須 false 位置 named 既定値 none パイプライン入力を許可する false ワイルドカード文字を許可する false -Encoding [] Specifies the type of character encoding used in the file. Valid values are "Unicode", "UTF7", "UTF8", "UTF32", "ASCII", "BigEndianUnicode", "Default", and "OEM". "Unicode" is the default. "Default" uses the encoding of the system's current ANSI code page. "OEM" uses the current original equipment manufacturer code page identifier for the operating system. 必須 false 位置 2 既定値 none パイプライン入力を許可する false ワイルドカード文字を許可する false -FilePath Specifies the path to the output file. 必須 true 位置 1 既定値 none パイプライン入力を許可する false ワイルドカード文字を許可する false -Force [] Allows the cmdlet to overwrite an existing read-only file. Even using the Force parameter, the cmdlet cannot ov erride security restrictions. 必須 false 位置 named 既定値 none パイプライン入力を許可する false ワイルドカード文字を許可する false -InformationAction [] 必須 false 位置 named 既定値 none パイプライン入力を許可する false ワイルドカード文字を許可する false -InformationVariable [] 必須 false 位置 named 既定値 none パイプライン入力を許可する false ワイルドカード文字を許可する false -InputObject [] Specifies the objects to be written to the file. Enter a variable that contains the objects or type a command o r expression that gets the objects. 必須 false 位置 named 既定値 none パイプライン入力を許可する true (ByValue) ワイルドカード文字を許可する false -NoClobber [] Will not overwrite (replace the contents) of an existing file. By default, if a file exists in the specified pa th, Out-File overwrites the file without warning. If both Append and NoClobber are used, the output is appended to the existing file. 必須 false 位置 named 既定値 none パイプライン入力を許可する false ワイルドカード文字を許可する false -Width [] Specifies 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 W indows PowerShell console is 80 (characters). 必須 false 位置 named 既定値 none パイプライン入力を許可する false ワイルドカード文字を許可する false -LiteralPath Specifies the path to the output file. Unlike FilePath, the value of the LiteralPath parameter is used exactly as it is typed. No characters are interpreted as wildcards. If the path includes escape characters, enclose it in single quotation marks. Single quotation marks tell Windows PowerShell not to interpret any characters as es cape sequences. 必須 true 位置 named 既定値 none パイプライン入力を許可する true (ByPropertyName) ワイルドカード文字を許可する false -Confirm [] Prompts you for confirmation before running the cmdlet.Prompts you for confirmation before running the cmdlet. 必須 false 位置 named 既定値 false パイプライン入力を許可する false ワイルドカード文字を許可する false -WhatIf [] Shows what would happen if the cmdlet runs. The cmdlet is not run.Shows what would happen if the cmdlet runs. T he cmdlet is not run. 必須 false 位置 named 既定値 false パイプライン入力を許可する false ワイルドカード文字を許可する false このコマンドレットは、次の共通パラメーターをサポートします: Verbose、 Debug、ErrorAction、ErrorVariable、WarningAction、WarningVariable、 OutBuffer, PipelineVariable、および OutVariable。詳細については、 about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216) を参照してください。 入力 System.Management.Automation.PSObject You can pipe any object to Out-File. 出力 None Out-File does not generate any output. メモ The Out cmdlets do not format objects; they just render them and send them to the specified display destination . If you send an unformatted object to an Out cmdlet, the cmdlet sends it to a formatting cmdlet before renderi ng it. The Out cmdlets do not have parameters for names or file paths. To send data to a cmdlet that contains the Out verb (an Out cmdlet), use a pipeline operator (|) to send the output of a Windows PowerShell command to the cmd let. You can also store data in a variable and use the InputObject parameter to pass the data to the cmdlet. Fo r help, see the examples. Out-File sends data, but it does not emit any output objects. If you pipe the output of Out-File to Get-Member, Get-Member reports that no objects have been specified. -------------------------- 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-Fil e creates it. Because the name of the FilePath parameter is optional, you can omit it and submit the equivalent com mand "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 pre vents an existing file from being overwritten. The output shows the error message that appears when NoClobber is us ed 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 forma t 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-Fi le 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 pa rameter to convert the output to ASCII format. It uses the Width parameter to limit each line in the file to 50 cha racters. Because the lines of output are truncated at 50 characters, the rightmost column in the process table is o mitted. -------------------------- 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 t he MyKey registry subkey (HKLM\Software\MyCompany\MyKey). A pipeline operator passes the result to the Out-File cmd let, 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 sys tem drive name, such as "c:", or the name of the provider followed by two colons, "FileSystem::", in the value of t he FilePath parameter. The second and third commands demonstrate these methods. 関連するリンク Online Version: http://go.microsoft.com/fwlink/p/?linkid=293996 Out-Default Out-Host Out-Null Out-Printer Out-String Tee-Object