Example I am following:
Get-ChildItem c:\scripts\*.* -include *.txt,*.log
https://technet.microsoft.com/en-us/library/ee176841.aspx
What gives? Why don't I get back a list of my test.txt files when I try to use include?
As a side note, what is c:\scripts\*.*
. It seems to be saying include a file with any name that has any format. But isn't that specified in the include? Anyway, more interested in why my seemingly basic code doesn't work.
To exclude directories, use the File parameter and omit the Directory parameter, or use the Attributes parameter. To get directories, use the Directory parameter, its "ad" alias, or the Directory attribute of the Attributes parameter. Gets files.
The Get-ChildItem cmdlet uses the Path parameter to specify the directory C:\Test . Get-ChildItem displays the files and directories in the PowerShell console. By default Get-ChildItem lists the mode (Attributes), LastWriteTime, file size (Length), and the Name of the item.
Use the Get-ChildItem cmdlet in PowerShell to get the full path of the file in the current directory. Get-ChildItem returns one or more items from the specified location and using the file FullName property, it gets the full path of the file.
Like the Windows command line, Windows PowerShell can use the dir command to list files in the current directory. PowerShell can also use the ls and gci commands to list files in a different format.
From the help file (Get-Help Get-ChildItem
):
The Include parameter is effective only when either the command includes the Recurse parameter or the path leads to the contents of a directory, such as C:\Windows*, where the wildcard character specifies the contents of the C:\Windows directory.
Get-ChildItem c:\pstest\*.* -include *.txt
or
Get-ChildItem c:\pstest -recurse -include *.txt
or better yet: use the -Filter
parameter instead of -Include
:
Get-ChildItem C:\pstest -Filter *.txt
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With