名前 Set-Content 概要 Writes or replaces the content in an item with new content. 構文 Set-Content [-Path] [-Value] [-Credential []] [-Encoding {Unknown | String | Unicode | Byte | BigEndianUnicode | UTF8 | UTF7 | UTF32 | Ascii | Default | Oem | BigEndianUTF32}] [-Exclude []] [-Filter []] [-Force] [-Include []] [-InformationAction {SilentlyContinue | Stop | Co ntinue | Inquire | Ignore | Suspend}] [-InformationVariable []] [-PassThru] [-Stream []] [-Confirm] [-WhatIf] [-UseTransaction []] [] Set-Content [-Value] [-Credential []] [-Encoding {Unknown | String | Unicode | Byte | Bi gEndianUnicode | UTF8 | UTF7 | UTF32 | Ascii | Default | Oem | BigEndianUTF32}] [-Exclude []] [-Filter []] [-Force] [-Include []] [-InformationAction {SilentlyContinue | Stop | Continue | Inquire | Ignore | Suspend}] [-InformationVariable []] [-PassThru] [-Stream []] -LiteralP ath [-Confirm] [-WhatIf] [-UseTransaction []] [] 説明 The Set-Content cmdlet is a string-processing cmdlet that writes or replaces the content in the specified item, s uch as a file. Whereas the Add-Content cmdlet appends content to a file, Set-Content replaces the existing conten t. You can type the content in the command or send content through the pipeline to Set-Content. パラメーター -Credential [] Specifies a user account that has permission to perform this action. The default is the current user. Type a user name, such as "User01" or "Domain01\User01", or enter a PSCredential object, such as one generate d by the Get-Credential cmdlet. If you type a user name, you will be prompted for a password. This parameter is not supported by any providers installed with Windows PowerShell. 必須 false 位置 named 既定値 none パイプライン入力を許可する true (ByPropertyName) ワイルドカード文字を許可する false -Encoding [] Type a user name, such as "User01" or "Domain01\User01", or enter a PSCredential object, such as one generate d by the Get-Credential cmdlet. If you type a user name, you will be prompted for a password. This parameter is not supported by any providers installed with Windows PowerShell. 必須 false 位置 named 既定値 none パイプライン入力を許可する false ワイルドカード文字を許可する false -Exclude [] Omits the specified items. The value of this parameter qualifies the Path parameter. Enter a path element or pattern, such as "*.txt". Wildcards are permitted. 必須 false 位置 named 既定値 none パイプライン入力を許可する false ワイルドカード文字を許可する false -Filter [] Specifies a filter in the provider's format or language. The value of this parameter qualifies the Path param eter. The syntax of the filter, including the use of wildcards, depends on the provider. Filters are more eff icient than other parameters, because the provider applies them when retrieving the objects, rather than havi ng Windows PowerShell filter the objects after they are retrieved. 必須 false 位置 named 既定値 none パイプライン入力を許可する false ワイルドカード文字を許可する false -Force [] Allows the cmdlet to set the contents of a file, even if the file is read-only. Implementation varies from pr ovider to provider. For more information, see about_Providers. Even using the Force parameter, the cmdlet can not override security restrictions. 必須 false 位置 named 既定値 none パイプライン入力を許可する false ワイルドカード文字を許可する false -Include [] Changes only the specified items. The value of this parameter qualifies the Path parameter. Enter a path elem ent or pattern, such as "*.txt". Wildcards are permitted. 必須 false 位置 named 既定値 none パイプライン入力を許可する false ワイルドカード文字を許可する false -InformationAction [] Type a user name, such as "User01" or "Domain01\User01", or enter a PSCredential object, such as one generate d by the Get-Credential cmdlet. If you type a user name, you will be prompted for a password. This parameter is not supported by any providers installed with Windows PowerShell. 必須 false 位置 named 既定値 none パイプライン入力を許可する false ワイルドカード文字を許可する false -InformationVariable [] Type a user name, such as "User01" or "Domain01\User01", or enter a PSCredential object, such as one generate d by the Get-Credential cmdlet. If you type a user name, you will be prompted for a password. This parameter is not supported by any providers installed with Windows PowerShell. 必須 false 位置 named 既定値 none パイプライン入力を許可する false ワイルドカード文字を許可する false -LiteralPath Specifies the path to the item that will receive the content. Unlike Path, the value of LiteralPath is used e xactly as it is typed. No characters are interpreted as wildcards. If the path includes escape characters, en close it in single quotation marks. Single quotation marks tell Windows PowerShell not to interpret any chara cters as escape sequences. 必須 true 位置 named 既定値 none パイプライン入力を許可する true(ByPropertyName) ワイルドカード文字を許可する false -PassThru [] Returns an object representing the content. By default, this cmdlet does not generate any output. 必須 false 位置 named 既定値 none パイプライン入力を許可する false ワイルドカード文字を許可する false -Path Specifies the path to the item that will receive the content. Wildcards are permitted. 必須 true 位置 1 既定値 none パイプライン入力を許可する true (ByPropertyName) ワイルドカード文字を許可する false -Stream [] Type a user name, such as "User01" or "Domain01\User01", or enter a PSCredential object, such as one generate d by the Get-Credential cmdlet. If you type a user name, you will be prompted for a password. This parameter is not supported by any providers installed with Windows PowerShell. 必須 false 位置 named 既定値 none パイプライン入力を許可する false ワイルドカード文字を許可する false -Value Specifies the new content for the item. 必須 true 位置 2 既定値 none パイプライン入力を許可する true (ByValue, 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. The cmdlet is not run. 必須 false 位置 named 既定値 false パイプライン入力を許可する false ワイルドカード文字を許可する false -UseTransaction [] Includes the command in the active transaction. This parameter is valid only when a transaction is in progres s. For more information, seeIncludes the command in the active transaction. This parameter is valid only whe n a transaction is in progress. For more information, see 必須 false 位置 named 既定値 false パイプライン入力を許可する false ワイルドカード文字を許可する false このコマンドレットは、次の共通パラメーターをサポートします: Verbose、 Debug、ErrorAction、ErrorVariable、WarningAction、WarningVariable、 OutBuffer, PipelineVariable、および OutVariable。詳細については、 about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216) を参照してください。 入力 System.Object You can pipe an object that contains the new value for the item to Set-Content. 出力 None or System.String When you use the Passthru parameter, Set-Content generates a System.String object representing the content. O therwise, this cmdlet does not generate any output. メモ You can also refer to Set-Content by its built-in alias, "sc". For more information, see about_Aliases. Set-Content is designed for string processing. If you pipe non-string objects to Set-Content, it converts the object to a string before writing it. To write objects to files, use Out-File. The Set-Content cmdlet is designed to work with the data exposed by any provider. To list the providers avail able in your session, type "Get-PsProvider". For more information, see about_Providers. -------------------------- EXAMPLE 1 -------------------------- PS C:\>set-content -path C:\Test1\test*.txt -value "Hello, World" This command replaces the contents of all files in the Test1 directory that have names beginning with "test" with "Hello, World". This example shows how to specify content by typing it in the command. -------------------------- EXAMPLE 2 -------------------------- PS C:\>get-date | set-content C:\Test1\date.csv This command creates a comma-separated variable-length (csv) file that contains only the current date and time. I t uses the Get-Date cmdlet to get the current system date and time. The pipeline operator passes the result to Se t-Content, which creates the file and writes the content. If the Test1 directory does not exist, the command fails, but if the file does not exist, the command will create it. -------------------------- EXAMPLE 3 -------------------------- PS C:\>(get-content Notice.txt) | foreach-object {$_ -replace "Warning", "Caution"} | set-content Notice.txt This command replaces all instances of "Warning" with "Caution" in the Notice.txt file. It uses the Get-Content cmdlet to get the content of Notice.txt. The pipeline operator sends the results to the F orEach-Object cmdlet, which applies the expression to each line of content in Get-Content. The expression uses th e "$_" symbol to refer to the current item and the Replace parameter to specify the text to be replaced. Another pipeline operator sends the changed content to Set-Content which replaces the text in Notice.txt with the new content. The parentheses around the Get-Content command ensure that the Get operation is complete before the Set operation begins. Without them, the command will fail because the two functions will be trying to access the same file. 関連するリンク Online Version: http://go.microsoft.com/fwlink/p/?linkid=293909 Add-Content Clear-Content Get-Content about_Providers