Just Getting Specific Files in PoSh–#SQLNewBlogger

Another post for me that is simple and hopefully serves as an example for people trying to get blogging as #SQLNewBloggers.

Just a quick one today, but a tip I hope I remember. While working on a script, I wanted to just get backup files in PoSh. I tried this:

Get-ChildItem -Path $BackupPath -File -Include *.bak

That got me this:

2019-09-23 10_06_19-cmd - powershell

Nothing.

Why not? Apparently, you need the –Recurse parameter, even though there are no subdirectories in this folder. A bug, IMHO, but who knows. In any case, adding the parameter makes things work. Thanks, SO.

2019-09-23 10_11_59-cmd - powershell

SQLNewBlogger

This was a quick 5 minute thing. After researching and testing for 10 minutes, and finding the solution, I wrote this up.

You could do that with anything you get working.

About way0utwest

Editor, SQLServerCentral
This entry was posted in Blog and tagged , , . Bookmark the permalink.

1 Response to Just Getting Specific Files in PoSh–#SQLNewBlogger

  1. Agostino says:

    From Microsoft https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-childitem?view=powershell-6:

    When the Include parameter is used, the Path parameter needs a trailing asterisk (*) wildcard to specify the directory’s contents.

    So for example, Get-Childitem -Path C:\Test\* -include P*.pdf
    or more briefly Get-Childitem -Path C:\Test\P*.pdf

    Cheers

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.