名前 Remove-Item 概要 Deletes the specified items. 構文 Remove-Item [-Path] [-Credential []] [-Exclude []] [-Filter []] [-Fo rce] [-Include []] [-Recurse] [-Stream []] [-Confirm] [-WhatIf] [-UseTransaction []] [] Remove-Item [-Credential []] [-Exclude []] [-Filter []] [-Force] [-Include []] [-Recurse] [-Stream []] -LiteralPath [-Confirm] [-WhatIf] [-UseTransactio n []] [] 説明 The Remove-Item cmdlet deletes one or more items. Because it is supported by many providers, it can delete many different types of items, including files, folders, registry keys, variables, aliases, and functions. パラメーター -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 generated by the Get-Credential cmdlet. If you type a user name, this cmdlet prompts you for a password. This parameter is not supported by any providers installed with Windows PowerShell. 必須 false 位置 named 既定値 none パイプライン入力を許可する true (ByPropertyName) ワイルドカード文字を許可する false -Exclude [] Specifies items that this cmdlet omits. The value of this parameter qualifies the Path parameter. Enter a p ath element or pattern, such as *.txt. Wildcard characters are permitted. 必須 false 位置 named 既定値 none パイプライン入力を許可する false ワイルドカード文字を許可する false -Filter [] Specifies a filter in the format or language of the provider. The value of this parameter qualifies the Pat h parameter. The syntax of the filter, including the use of wildcard characters, depends on the provider. F ilters are more efficient than other parameters, because the provider applies them when it retrieves the ob jects, instead of having Windows PowerShell filter the objects after they are retrieved. 必須 false 位置 named 既定値 none パイプライン入力を許可する false ワイルドカード文字を許可する false -Force [] Forces the cmdlet to remove items that cannot otherwise be changed, such as hidden or read-only files or re ad-only aliases or variables. The cmdlet cannot remove constant aliases or variables. Implementation varies from provider to provider. For more information, see about_Providers. Even using the Force parameter, the cmdlet cannot override security restrictions. 必須 false 位置 named 既定値 none パイプライン入力を許可する false ワイルドカード文字を許可する false -Include [] Specifies items to delete. The value of this parameter qualifies the Path parameter. Enter a path element o r pattern, such as *.txt. Wildcard characters are permitted. 必須 false 位置 named 既定値 none パイプライン入力を許可する false ワイルドカード文字を許可する false -LiteralPath Specifies a path of the items being removed. Unlike Path, the value of the LiteralPath parameter is used ex actly as it is typed. No characters are interpreted as wildcard characters. If the path includes escape cha racters, enclose it in single quotation marks. Single quotation marks tell Windows PowerShell not to interp ret any characters as escape sequences. 必須 true 位置 named 既定値 None パイプライン入力を許可する true(ByPropertyName) ワイルドカード文字を許可する false -Path Specifies a path of the items being removed. Wildcard characters are permitted. 必須 true 位置 1 既定値 none パイプライン入力を許可する true (ByValue, ByPropertyName) ワイルドカード文字を許可する false -Recurse [] Indicates that this cmdlet deletes the items in the specified locations and in all child items of the locat ions. When it is used with the Include parameter, the Recurse parameter might not delete all subfolders or all ch ild items. This is a known issue. As a workaround, try piping results of the Get-ChildItem -Recurse command to Remove-Item, as described in Example 4 in this topic. 必須 false 位置 named 既定値 none パイプライン入力を許可する false ワイルドカード文字を許可する false -Stream [] Specifies an alternative data stream from a file that this cmdlet deletes. This cmdlet does not delete the file. Enter the stream name. Wildcard characters are supported. This parameter is not valid on folders. The Stream parameter is a dynamic parameter that the FileSystem provider adds to Remove-Item. This paramete r works only in file system drives. You can use Remove-Item to delete an alternative data stream. However, it is not the recommended way to eli minate security checks that block files that are downloaded from the Internet. If you verify that a downloa ded file is safe, use the Unblock-File cmdlet. This parameter was introduced in Windows PowerShell 3.0. 必須 false 位置 named 既定値 none パイプライン入力を許可する false ワイルドカード文字を許可する false -Confirm [] Prompts you for confirmation before running the cmdlet.Prompts you for confirmation before running the cmdl et. 必須 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 run s. 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 progr ess. For more information, seeIncludes the command in the active transaction. This parameter is valid only when 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.String You can pipe a string that contains a path, but not a literal path, to this cmdlet. 出力 None This cmdlet does not return any output. メモ You can also refer to Remove-Item by any of its built-in aliases: del, erase, rmdir, rd, ri, or rm. For mor e information, see about_Aliases. Remove-Item cmdlet is designed to work with the data exposed by any provider. To list the providers availab le in your session, type Get-PsProvider. For more information, see about_Providers. Example 1: Delete files that have any file name extension PS C:\>Remove-Item C:\Test\*.* This command deletes all of the files that have names that include a dot (.) from the C:\Test folder. Because t he command specifies a dot, the command does not delete folders or files that have no file name extension. Example 2: Delete some of the document files in a folder PS C:\>Remove-Item * -Include *.doc -Exclude *1* This command deletes from the current folder all files that have a .doc file name extension and a name that doe s not include 1. It uses the wildcard character (*) to specify the contents of the current folder. It uses the Include and Exclude parameters to specify the files to delete. Example 3: Delete hidden, read-only files PS C:\>Remove-Item -Path C:\Test\hidden-RO-file.txt -Force This command deletes a file that is both hidden and read-only. It uses the Path parameter to specify the file. It uses the Force parameter to delete it. Without Force, you cannot delete read-only or hidden files. Example 4: Delete files in subfolders recursively PS C:\>Get-ChildItem * -Include *.csv -Recurse | Remove-Item This command deletes all of the CSV files in the current folder and all subfolder recursively. Because the Recurse parameter in Remove-Item has a known issue, the command in this example uses Get-ChildItem to get the desired files, and then uses the pipeline operator to pass them to Remove-Item. In the Get-ChildItem command, Path has a value of *, which represents the contents of the current folder. It us es Include to specify the CSV file type, and it uses Recurse to make the retrieval recursive. If you try to specify the file type the path, such as -Path *.csv, the cmdlet interprets the subject of the sea rch to be a file that has no child items, and Recurse fails. Example 5: Delete subkeys recursively PS C:\>Remove-Item hklm:\software\mycompany\OldApp -Recurse This command deletes the OldApp registry key and all its subkeys and values. It uses Remove-Item to remove the key. The path is specified, but the optional parameter name (Path) is omitted. The Recurse parameter deletes all of the contents of the OldApp key recursively. If the key contains subkeys an d you omit the Recurse parameter, you are prompted to confirm that you want to delete the contents of the key. 関連するリンク Online Version: http://go.microsoft.com/fwlink/p/?linkid=293896 Clear-Item Copy-Item Get-Item Invoke-Item Move-Item New-Item Remove-ItemProperty Rename-Item Set-Item