• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

Clatent

Technology | Fitness | Food

  • About
  • Resources
  • Contact

Get-ChildItem

One-Liner Wednesday December 7, 2022

December 7, 2022 by ClaytonT Leave a Comment

Today’s one liner is another basic one, but very powerful. Ever need to look for a file, or better yet multiple files then need to rename or delete them?

Get-Childitem -Path C:\windows -Recurse -Filter *test* -erroraction SilentlyContinue  | out-gridview -PassThru | Remove-Item -WhatIf

What this one liner will do is search all of the folders/files in the C:\Windows directory that have the word test in the file name or folder. It will even pull things like memtest.efi.mui and Microsoft.Windows.RemoteAttestation.Core.dll. The stars basically tell the search I can’t remember what else is after and/or before the letters I put, but I know there are letters there. Then with its results will put it into a nice window that you can select which file(s) you want to delete. Once you have highlighted the files/folders you want to delete, you can press ok, then they will be deleted(You will need to remove the “-WhatIf” from my code above because I like you, and just in case you just run this without double checking, files don’t get deleted)

Another thing to note is that I put the -Recurse parameter after the folder, this tells PowerShell to search sub directories too. If you remove it, it will only search that current directory.

And this can be used in the registry as well, just make sure that -WhatIf is used until you are 100% the code is working correctly.

Microsoft Learn:
Get-ChildItem

Tagged With: Get-ChildItem, One Liner Wednesday, PowerShell

Primary Sidebar

Clayton Tyger

Tech enthusiast dad who has lost 100lbs and now sometimes has crazy running/biking ideas. Read More…

Find Me On

  • Email
  • GitHub
  • Instagram
  • LinkedIn
  • Twitter

Recent Posts

  • One-Liner Wednesday January 25, 2023
  • Module Monday January 23, 2023
  • One-Liner Wednesday January 18, 2023
  • Module Monday January 16, 2023
  • Read-Only Friday January 13, 2023

Categories

  • 365
  • Active Directory
  • Cim
  • Dashboards
  • Documentation
  • Get-WMI
  • Learning
  • Module Monday
  • Nutanix
  • One Liner Wednesday
  • Passwords
  • PDF
  • PowerShell
  • Read-Only Friday
  • Reporting
  • Security
  • Windows
  • WSUS

© 2023 Clatent