Powershell on the Way to Work–Part 5


Oh hey.  Back again are you?  Good thing too.  Flat tire so I’m stuck on side while the Tow Truck driver changes my tire….

So let me take a few minutes today and show you a pretty cool Cmdlet called GET-CHILDITEM.

If you remember a bit back, I showed you how typing DIR executes a GET-CHILDITEM.

So you might think “Ah! GET-CHILDITEM is Powershell’s version of DIR!”

You might think that but it wouldn’t be accurate.  I could get into great descriptions about Objects and DotNet but then you would fall asleep and my head my explode.    So let me show you some things GET-CHILDITEM can do and YOU can decide just what it is.

First off, it’s not only good for the File System.   It can access what the Powershell world refers to as “Providers”.   The File system is only one. 

For example if I do

GET-CHILDITEM C:\

You see a file directory of C:\ but I can also do this

GET-CHILDITEM HKCU:

Which will dump all of the keys in the Root of HKEY_CURRENT_USER

GET-CHILDITEM CERT:

Which will give me the ability to access my certificates.  There are others it can do as well.   We can access the built in Environment variables in Windows (Remember all stuff we used to access in DOS?  Yep! Nothing lost!) or even Navigate and filter on a much higher level.

So it IS a Directory Cmdlet in a sense.  It will much of the content that you want.   To call it directory is not precise but it does meet our needs as the IT Pro.   Now let’s show you something neat it can do.   Like the old DIR it can recurse

GET-CHILDITEM C:\ –recurse

But we can also filter and say “Only give me these file types”

GET-CHILDITEM C:\ –recurse –include *.txt, *.ini

Or this was a neat one I ran across.   Go through a structure and show me ONLY files or ONLY directories

GET-CHILDITEM C:\ –directory

GET-CHILDITEM C:\ –file

You can even combine this bits together

GET-CHILDITEM – C:\SomeFolder –recurse –directory

By default hidden files like System are still hidden but you can view them with a –force added on

GET-CHILDITEM –C:\ –Force

GET-CHILDITEM is an incredibly Powerful Cmdlet.   I’m betting you’re seeing what I did as an ITPro.  That even if I didn’t learn to script, just knowing this means I COULD have a far more powerful search tool on me.   But it get’s better.    You could actually delete files in Powershell based upon Date Time in only two lines.   But we’ll get into that later.  

For now, the tire is back on the car.  Back to work and we’ll chat soon.

DSC_0158 (640x425)_thumb

Sean Kearney
Twitter: @energizedtech
www.powershell.ca

Comments (0)

Skip to main content