라벨이 ForEach인 게시물 표시

File searching and Remove the searched files in Powershell

This is very useful when you are managing your files in your computer (Windows) 1. Identify files in certain folder >>> Get-ChildItem C:/testfolder/* 2. Identify files in certain folder and remove all of them >>> Get-ChildItem C:/testfolder/* | ForEach ($_) {Remove-Item $_.fullname} 3. Search certain files including '.test' >>> Get-ChildItem C:/* -Include *.test 4. Search certain files including '.test', but excluding the files which begin with 'abc' >>> Get-ChildItem C:/* -Include *.test -Exclude abc*.test 5. Search the files including Sub folders >>> Get-ChildItem C:/* -Include *.test -Recurse 6. Search the files including Sub folders and remove all of them >>> Get-ChildItem C:/* -Include *.test -Recurse | ForEach ($_) {Remove-Item $_.fullname} 7. Search the files, Print them, and then remove all of them >>> Get-ChildItem C:/* -Include *.test -Recurse || ForEach (

ForEach in Powershell

ForEach - Loop statement Syntax is as below. ForEach (item In collection) {ScriptBlock} item: A variable to hold the current item collection: A collection of objects e.g. filenames, registry keys, servernames ScriptBlock: A block of script to run against each object. Thanks, Have Fun! The source: http://ss64.com/ps/foreach.html