Remove-Item für Dateisystem

Letzte Aktualisierung: Mai 2014

Betrifft: Windows PowerShell 2.0, Windows PowerShell 3.0, Windows PowerShell 4.0

Löscht Dateien und Ordner.

Syntax

Remove-Item [-Stream <string>] [<CommonParameters>]

Beschreibung

In Dateisystemlaufwerken löscht das Cmdlet Remove-Item Dateien und Ordner.

Wenn Sie den dynamischen Stream-Parameter verwenden, löscht den angegebenen alternativen Datenstrom, aber die Datei wird nicht gelöscht.

Hinweis: Diese Hilfedatei benutzerdefinierter Cmdlets erläutert, wie das Cmdlet Remove-Item in einem Dateisystemlaufwerk arbeitet. Informationen zum Cmdlet Remove-Item in allen Laufwerken erhalten Sie durch Eingabe von "Get-HelpRemove-Item -Path $null" oder in Remove-Item unter https://go.microsoft.com/fwlink/?LinkID=113373.

Parameter

-Stream <string>

Löscht den angegebenen alternativen Datenstrom aus einer Datei, aber die Datei wird nicht gelöscht. Geben Sie den Namen des Stroms ein. Platzhalter werden unterstützt. Dieser Parameter gilt nicht für Ordner.

Stream ist ein dynamischer Parameter, den der FileSystem-Anbieter zum Remove-Item-Cmdlet hinzufügt. Dieser Parameter funktioniert nur in Dateisystemlaufwerken.

Sie können das Remove-Item-Cmdlet zum Löschen eines alternativen Datenstroms verwenden. Es ist jedoch nicht die empfohlene Methode, Sicherheitsüberprüfungen zu deaktivieren, die Dateien blockieren, die aus dem Internet heruntergeladen werden. Wenn Sie überprüfen, ob eine heruntergeladene Datei sicher ist, verwenden Sie das Unblock-File-Cmdlet.

Dieser Parameter wird in Windows PowerShell 3.0 eingeführt.

Erforderlich?

falsch

Position?

benannt

Standardwert

Pipelineeingaben akzeptieren?

falsch

Platzhalterzeichen akzeptieren?

falsch

<CommonParameters>

Dieses Cmdlet unterstützt folgende allgemeine Parameter: -Debug, -ErrorAction, -ErrorVariable, -OutBuffer, -OutVariable, -Verbose, -WarningAction und -WarningVariable. Weitere Informationen finden Sie unter about_CommonParameters.

Ein- und Ausgaben

Der Eingabetyp ist der Typ der Objekte, die an das Cmdlet übergeben werden können. Der Rückgabetyp ist der Typ der Objekte, die das Cmdlet zurückgibt.

Eingaben

Ausgaben

Beispiel 1

C:\PS>Get-Item C:\Test\Copy-Script.ps1 -Stream Zone.Identifier


   FileName: \\C:\Test\Copy-Script.ps1

Stream                   Length
------                   ------
Zone.Identifier              26


C:\PS>Remove-Item C:\Test\Copy-Script.ps1 -Stream Zone.Identifier

C:\PS>Get-Item C:\Test\Copy-Script.ps1 -Stream Zone.Identifier

get-item : Could not open alternate data stream 'Zone.Identifier' of file 'C:\Test\Copy-Script.ps1'.
At line:1 char:1
+ get-item 'C:\Test\Copy-Script.ps1' -Stream Zone.Identifier
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\Test\Copy-Script.ps1:String) [Get-Item], FileNotFoundE
   xception
    + FullyQualifiedErrorId : AlternateDataStreamNotFound,Microsoft.PowerShell.Commands.GetItemCommand


C:\PS>Get-Item C:\Test\Copy-Script.ps1


    Directory: C:\Test


Mode                LastWriteTime     Length Name
----                -------------     ------ ----
-a---          8/4/2011  11:15 AM       9436 Copy-Script.ps1

Description
-----------
This example shows how to use the Stream dynamic parameter of the Remove-Item cmdlet to delete an alternate data stream. The stream parameter is introduced in Windows PowerShell 3.0.

The first command uses the Stream dynamic parameter of the Get-Item cmdlet to get the Zone.Identifier stream of the Copy-Script.ps1 file. 

The second command uses the Stream dynamic parameter of the Remove-Item cmdlet to remove the Zone.Identifier stream of the file.

The third command uses the Stream dynamic parameter of the Get-Item cmdlet to verify that the Zone.Identifier stream is deleted.

The fourth command Get-Item cmdlet without the Stream parameter to verify that the file is not deleted.





Beispiel 2

C:\PS>Remove-Item C:\Test\*.*

Description
-----------
This command deletes all of the files with names that include a dot (.) from the C:\Test directory. Because the command specifies a dot, the command does not delete directories or files with no file name extension.





Beispiel 3

C:\PS>Remove-Item * -Include *.doc -Exclude *1*

Description
-----------
This command deletes from the current directory all files with a .doc file name extension and a name that does not include "1". It uses the wildcard character (*) to specify the contents of the current directory. It uses the Include and Exclude parameters to specify the files to delete.





Beispiel 4

C:\PS>Remove-Item -Path C:\Test\hidden-RO-file.txt -Force

Description
-----------
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 give permission to delete it. Without Force, you cannot delete read-only or hidden files.





Beispiel 5

C:\PS>Get-ChildItem * -Include *.csv -Recurse | Remove-Item

Description
-----------
This command deletes all of the CSV files in the current directory and all subdirectories recursively.

Because the Recurse parameter in this cmdlet is faulty, the command uses the Get-Childitem cmdlet to get the desired files, and it uses the pipeline operator to pass them to the Remove-Item cmdlet.

In the Get-ChildItem command, the Path parameter has a value of *, which represents the contents of the current directory. It uses the Include parameter to specify the CSV file type, and it uses the Recurse parameter to make the retrieval recursive.

If you try to specify the file type in the path, such as "-path *.csv", the cmdlet interprets the subject of the search to be a file that has no child items, and Recurse fails.





See Also

Concepts

FileSystem Provider

Other Resources

Clear-Content
Get-Content
Get-ChildItem
Get-Content
Get-Item
Remove-Item
Set-Content
Test-Path