Get All Files with a Certain Extension
# add '-recurse' to include sub folders
Get-ChildItem -Path $directory -Filter "*.CSV"
Details
This command will return all the files in a directory and returns the ones that match the filter criteria. Include ‘-recurse’ parameter to also return sub folders

Example
PS C:\> $directory = "C:\temp"
>> Get-ChildItem -Path $directory -Filter "*.CSV"



    Directory: C:\temp


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----        6/19/2019  11:45 AM         528685 temp01.csv
-a----        6/19/2019  11:45 AM         528685 temp02.csv

  |  
Get All Folders in a Directory
# add '-recurse' to include sub folders
Get-ChildItem -Path $directory -Directory
Details
This command will return all the folders in a directory, and does not return the files. Include ‘-recurse’ parameter to also return sub folders

Example
PS C:\> $directory = "C:\temp"
>> Get-ChildItem -Path $directory -Directory



    Directory: C:\temp


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----        6/19/2019  12:53 PM                Logs

  |  
Get All Files in a Directory
# add '-recurse' to include sub folders
Get-ChildItem -Path $directory -File
Details
This command will return all the files in a directory, and does not return the folders. Include ‘-recurse’ parameter to also return sub folders

Example
PS C:\> $directory = "C:\temp"
>> Get-ChildItem -Path $directory -File



    Directory: C:\temp


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----        6/19/2019  11:45 AM         528685 temp01.csv
-a----        6/19/2019  11:45 AM         528685 temp02.csv

  |  
Get All Files and Folders in a Directory
# add '-recurse' to include sub folders
Get-ChildItem -Path $directory
Details
This command will return all the files and folders in a directory. Include ‘-recurse’ parameter to also return sub folders

Example
PS C:\> $directory = "C:\temp"
>> Get-ChildItem -Path $directory



    Directory: C:\temp


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----        6/19/2019  12:53 PM                Logs
-a----        6/19/2019  11:45 AM         528685 temp01.csv
-a----        6/19/2019  11:45 AM         528685 temp02.csv

  |