poweshell:: remove-item options

Remove-Item -Path D:\repo\files\*.* -Recurse
Remove-Item -Path D:\repo\files -Recurse       #files folder삭제

 

 

Remove Files in Folder and SubFolders

Remove-Item -Path D:\repo\files\*.* -Recurse


# Delete all files from the folder D:\repo\files and it's subfolders
Remove-Item -Path D:\repo\files\ -Recurse -Include *.*

Get-ChildItem -Path D:\repo\files\ -File -Recurse | Remove-Item

 

 

 

Delete a file

-Path Specify the path of the items that need to be removed.
-LiteralPath The exact path the item
-Include Specifies a path element to include, for example, *.txt
-Exclude Specifies a path element to exclude, for example, *.txt
-Recurse Delete items in the specified location and in all subfolders
-Force Used to delete read-only files or hidden items
-Confirm Prompt for confirmation

 

Remove-Item -Path D:\repo\\readme.MD

 

Delete all Files in a Folder 

Remove-Item -Path D:\repo\files\*.*

Get-ChildItem -Path D:\repo\files\ -File | Remove-Item

 

Delete File if Exists

$file = D:\repo\files\readme.MD

if (Test-Path -Path $file) {
    Remove-Item -Path $file
}

 

 

 

 


Using the Include Filter / Excluid Filter

# Remove all .log items
Remove-Item -Path C:\temp\files\ -Include *.log


# Get all files that have the word app or process in their name.
Remove-Item -Path C:\temp\files\ -Include *app*, *process* -Recurse



Remove-Item -Path C:\temp\files\ -Include *.log -Exclude *process* -Recurse

 

 

 

 

 

https://lazyadmin.nl/powershell/powershell-delete-file/

 

How to Delete a File with PowerShell Remove-Item — LazyAdmin

Learn how to delete files with PowerShell using different selection methods, based on file size, age or filter on (part of) filename.

lazyadmin.nl

 

_

반응형