In this tutorial, you will learn how to list files, folders, and subfolders using Windows CMD commands and PowerShell.
I’ll also demonstrate using the NTFS Permissions Tool, which is a graphical program that displays the permissions on folders and subfolders.
In this article
Check it out.
List Files and folders using the DIR Command
The dir command is built into all versions of Windows. It is an easy to use command to list files, folders, and subfolders from the Windows command prompt.
Let’s look at some examples.
Example 1. List files and folders in the current directory
To list the files and folders in the current directory, open the Windows command prompt, enter dir and press enter. The dir command by default does not display subfolders.
dirIn this example, my current location is c:\it, so when I run the dir command it will list everything in this folder.

I have put the command output into colored boxes to explain what each column means.
- Red = This column is the last modified date of the file or folder
- Green = Indicates if the item is a folder, folders are labeled with DIR
- Purple = The size of the file
- Yellow = Name of the file or folder.
Example 2. List subfolders
Use the /s option to include subfolders.
dir /sI ran the command from the c:\it location and it lists all subfolders and files from this directory. I’ve highlighted some of the subfolders in the screenshot below.

Example 3. Specify a directory path
To list files and folders from a specific directory enter the complete directory path.
dir /s c:\itFor example, if my current location is the root of c: and I type dir /s c:\it the command will display the items from the c:\it directory.

Example 4. Export list of files and folders
To export the screen output use the command below. You can name the file whatever you want, in this example, I named the file files2.txt
dir > files2.txtThe file will be saved to the current directory.

Pretty easy right?
I covered some of the most basic dir command options. To see a full list of options type dir /? and press enter.

Display Folder Structure using TREE Command
The tree command is another built-in Windows command. This command will display the contents of a directory in a tree structure. This can be useful to give you an overview of the folder layout.
You must specify a path or this command will start at the root of c
Example 1. List all folders and subfolders using TREE
To list all folders and subfolders enter the tree command and the path.
tree c:\it\toolkit
Example 2. List all folders and files using TREE
To include files with the tree command use the /f option.
tree c:\it\toolkit /f
In my experience, I never use the tree command. I find it more useful when a command provides more details like modified dates, permissions, ownership, and so on. If you just need to see the files and folders with no other details then this is a great option.
Powershell List Folders and Subfolders
You can use the Get-Childitem PowerShell cmdlet to list files and folders. The Get-Childitem cmdlet is similar to dir but much more Powerful.
Let’s look at some examples
Example 1. List files and folders using Get-Childitem
This example gets the folder contents from a specific directory
Get-ChildItem -path c:\it\toolkit
By default, the Get-ChildItem cmdlet lists the mode, LastWriteTime, Length, and Name of the filer or folder.
- l = Link
- d – directory
- a = archive
- r = read-only
- h = hidden
- s = system
Example 2. Get subfolders using Get-ChildItem
Use the -Recurse option to get subfolders and files.
Get-ChildItem -path c:\it\toolkit -Recurse
Example 3. Get items using the Depth parameter
You can use the -Depth parameter to control how many subfolders deep to include in the list.
Get-ChildItem -Path C:\it -Depth 2Example 4. PowerShell List only specific file types
In this example, I will list only files that end in a .msi file extension. This will search all subfolders in the directory path.
get-childitem -path c:\it -include *.msi -recurse
Example 5. PowerShell List only folder or files name
The -Name parameter will only return the file or folder name.
Get-ChildItem -path c:\it\toolkit -Name
Example 6. PowerShell List all Files and Folder Details
To display all details of a file or folder use the fl option.
Get-ChildItem -path c:\it\toolkit | FLYou can see below this command will display additional details, if there are any.

Example 7. PowerShell count files and folders
To get a count of the files and folders use the measure-object option.
Get-ChildItem -path c:\it\toolkit | Measure-Object
Example 8. Powershell Get Folder Size
You can also use the measure-object option to get the folder size.
Get-ChildItem -path c:\it\toolkit | Measure-Object -Property Length -sum
As you can see using PowerShell there are a lot of options when it comes to getting files and folders, you can create some really powerful reports.
Get Folder and Subfolder NTFS Permissions
If you need a report of folders and subfolders that includes who has permission to what, then check out the NTFS Permissions Reporting Tool below.
Example 1. List NTFS Permissions on Shared Folder

- DirectoryName = Path of the folder
- Account = Account listed on the folder (this can be a user or group)
- DirectoryOwner = Owner listed on the folder
- DirectoryRights = Permissions the user or group has to the folder
- Type = Allow or Deny
- AppliesTo = What the permissions applies to
- IsInherited = Are the permissions inherited from a parent folder
Example 2. List Folder Permissions on Local Folder
If you want to check the permissions on a local folder click the browse button or enter the folder path.

Which Command Will You Use?
In this article, I showed you three different commands to get files, folders, and subfolders.
Which command did you find most useful? Let me know in the comments below.
Related Articles
It is easy to get files from a folder using PowerShell based on some conditions. In this PowerShell tutorial, I will show you multiple methods to get the first 10 files in a folder using PowerShell, ordered by their last modified date.
Method 1: Using Get-ChildItem and Sort-Object
To get the first 10 files in a folder using PowerShell, you need to get the files and then sort them by their last modified date.
The simplest ways to retrieve files and sort them by their last modified date is by using the Get-ChildItem cmdlet in combination with Sort-Object and Select-Object.
Here is the complete PowerShell script.
# Define the path to the folder
$folderPath = "C:\MyFolder"
# Get the first 10 files ordered by last modified date in descending order
Get-ChildItem -Path $folderPath | Sort-Object -Property LastWriteTime -Descending | Select-Object -First 10In this example:
Get-ChildItemretrieves all files and directories in the specified folder.Sort-Objectsorts the items by theLastWriteTimeproperty in descending order.Select-Objectselects the first 10 items from the sorted list.
You can see I executed the PowerShell script using VS code, and it sent me the first 10 files from the folder.

Method 2: Using Get-ChildItem with Where-Object
If you want to filter files before getting the first 10 files from a folder using PowerShell, then you can use the Get-ChildItem with Where-Object cmdlets.
Here is the complete PowerShell script.
# Define the path to the folder
$folderPath = "C:\MyFolder"
# Get the first 10 files modified in the last 30 days, ordered by last modified date
Get-ChildItem -Path $folderPath | Where-Object { $_.LastWriteTime -gt (Get-Date).AddDays(-30) } | Sort-Object -Property LastWriteTime -Descending | Select-Object -First 10In this example:
Where-Objectfilters the files to include only those modified in the last 30 days.- The rest of the pipeline remains the same as in Method 1.
You can see the output like in the below screenshot after I executed the script using VS code.

Method 3: Recursive Search with -Recurse
If you want to get the files from subfolders also, then you can use the -Recurse parameter with Get-ChildItem cmdlet.
Here is the complete PowerShell script.
# Define the path to the folder
$folderPath = "C:\MyFolder"
# Get the first 10 files from the folder and its subfolders, ordered by last modified date
Get-ChildItem -Path $folderPath -Recurse | Sort-Object -Property LastWriteTime -Descending | Select-Object -First 10In this example:
- The
-Recurseparameter makesGet-ChildItemsearch within all subfolders. - The rest of the pipeline remains the same as in Method 1.
Method 4: Using ForEach-Object
In PowerShell, you can also use the PowerShell ForEach-Object cmdlet to get the first 10 files from a folder.
Here is complete example.
# Define the path to the folder
$folderPath = "C:\MyFolder"
# Initialize a counter
$counter = 0
# Process each file and break after 10 files
Get-ChildItem -Path $folderPath | Sort-Object -Property LastWriteTime -Descending | ForEach-Object { if ($counter -lt 10) { $_ $counter++ } else { break } }In this example:
ForEach-Objectprocesses each file individually.- A counter is used to keep track of the number of files processed.
- The loop breaks after 10 files have been processed.
I executed the complete PowerShell script, and you can see the output in the screenshot below:

Conclusion
I hope you can use the above methods to get the first 10 files from a folder using PowerShell. The PowerShell cmdlets are like: Get-ChildItem, Sort-Object, and Select-Object, etc.
i know there are lots of threads already to this topic and i tried to put all the ideas into my powershell code as well to make get-childitem less memory hungry but still it eats up a lot of memory.
Here is my thing: Having a directory with more than 10 Mio sub directories that i need to go through using get-childitem. Memory consumption goes up to more than 50GB and at some point i got to kill the process not killing my server.
Here is my code. It recursively searches for some xml files (each sub directory has one) and if it found that xml file, read the content and add some values to two variables ($a and $b). I need the try-catch because sometimes the xml files are corrupt and don’t have the desired information.
$a = $b = 0
gci -Recurse -File -Filter "file.xml" -path C:\dir\ | ForEach-Object { try { $FullName = $_.FullName [xml]$content = gc $_.FullName $a += ($content.Directory.File | % {$_.Size} | measure-object -sum).sum $b += $content.Directory.File.count } catch { (Get-date -Format "MMM dd HH:mm:ss") + " Error: Problem executing " + $FullName + ". Error message: " + $_.Exception.Message | Out-File $LogFile -Append }
}Anyone got an idea to make it run with less memory usage?
Edit:
This is an example xml file that it searches for
<?xml version="1.0" encoding="utf-8"?>
<Directory> <File Name="xxxxxx.doc"> <Size>22222</Size> <CreationTime>xxxxxxxxx</CreationTime> </File> <File Name="yyyyy.doc"> <Size>11111</Size> <CreationTime>20140723141441</CreationTime> </File>
</Directory>
Locating specific files quickly then becomes critical for tasks like troubleshooting, reporting, retention, and more. Yet traversing folder structures manually to find target files can be incredibly tedious and time-consuming.
In this comprehensive guide, I will demonstrate step-by-step how to leverage PowerShell to efficiently retrieve all files stored in a folder structure. We will cover the basics of PowerShell, the ‘Get-ChildItem’ cmdlet, and various methods for retrieving files from a folder.
Introduction to PowerShell File Management
In managing a Windows operating system, PowerShell emerges as a potent tool, offering an extensive range of capabilities for automating tasks and managing files. One common task that we often need to perform is retrieving a listing of files from a specific folder. When it comes to file management, PowerShell provides a set of cmdlets that allow you to create, delete, copy, move, and modify files and folders. These cmdlets provide a flexible and efficient way to manage files and folders from the command line.
Why to get a List of Files?
You may need to get a list of files in a particular folder using PowerShell for many reasons. Here are some common examples:
- Collect logs or reports – By grabbing all files, such as .log or .csv files, in a logs or reports directory, you can compile the data for analysis.
- Backup files – Getting a list of files allows you to then copy or move them to another location for backup purposes.
- Process files – Retrieve files from a folder in order to process them in some way, like loading them into a database.
- File management – You may want to get all files to organize them better, delete old ones, check for duplicates, etc.
Understanding the ‘Get-ChildItem’ cmdlet in PowerShell
The ‘Get-ChildItem’ cmdlet is a PowerShell cmdlet that retrieves all child items (files and folders) in a specified location. It is one of the most commonly used cmdlets in PowerShell and is used to navigate the file system, retrieve files, and get information about files and folders.
The ‘Get-ChildItem’ cmdlet or its alias DIR/LS has several parameters that allow you to specify the location of the items to retrieve, the type of items to retrieve, and how to display the items. For example, you can use the ‘-Path’ parameter to specify the folder to retrieve items from, and the ‘-Recurse’ parameter to retrieve items from all subfolders. This cmdlet supports the -Filter, -Include, and -Exclude parameters. The basic syntax is:
Get-ChildItem [-Path] <String[]> [[-Filter] <String>] [-Include <String[]>] [-Exclude <String[]>] [-Recurse] [<CommonParameters>]
To list files and folders in a specific directory, simply provide the path as an argument to the Get-ChildItem cmdlet. You can also use wildcards to filter the results based on specific file names or extensions.
In addition, Get-ChildItem offers various parameters that allow you to further refine your search criteria, such as specifying the maximum depth or excluding hidden items. This cmdlet can help to work with various PowerShell providers and specified locations, such as a file system directory, registry hive, or certificate store.
This command not only lists files and directories at a specified location but also allows for filtering and recursive searches across subdirectories. We can further refine our file search by employing various parameters and options available within PowerShell to pinpoint precisely the files we need.
To get all files in a folder using PowerShell, you can use the ‘Get-ChildItem’ cmdlet with the ‘-File’ parameter. This parameter specifies that you want to retrieve only files, not folders.
Here is an example of how to use the ‘Get-ChildItem’ cmdlet to retrieve all files in a folder:
Get-ChildItem -Path "C:\Documents" -File
This command uses the Path parameter to retrieve all files in the ‘C:\Documents’ folder. In the result window, You will see a list of all files in the folder, including the file name, directory, and size.

You can also use the -Recurse parameter to search for files in subfolders of the specified folder. For example, let’s use PowerShell to list files in a directory recursively:
$AllFiles = Get-ChildItem C:\Documents -File -Recurse
This will get all files of C:\Documents as well as, in all child containers.
Filtering Files in PowerShell
When working with PowerShell, the Get-ChildItem cmdlet is a powerful tool for retrieving files and folders within a specified directory. However, you might often find yourself needing to filter the items retrieved from a folder based on specific criteria. This is where the various parameters of Get-ChildItem come into play.
Here is an example of how to use the -Filter parameter to specify a search pattern for the files you want to retrieve:
$TextFiles = Get-ChildItem C:\Docs -File -Filter "*.txt"
This will return only files with the .txt extension.
Filtering by Attributes
We can also filter our search based on file attributes such as ReadOnly, Hidden, System, Device, Temporary, and Directory.
Get-ChildItem -Path "C:\Documents" -Recurse -Attributes ReadOnly
To combine multiple attributes, we use commas to separate them.
Get-ChildItem -Path "C:\Documents" -Recurse -Attributes Hidden,System
By mastering these advanced file search techniques, we streamline our efforts in PowerShell, ensuring that file management is not just doable but efficient.
Including and Excluding Files
In addition to the ‘-Filter’ parameter, Get-ChildItem also provides other parameters, such as ‘-Include’ and ‘-Exclude’, which allow you to further refine your search. These parameters enable you to include or exclude specific files or folders from the results, as well as search for items in subdirectories.
We may also refine our file retrieval by including or excluding specific files. The Include and Exclude parameters work in conjunction with Get-ChildItem to match or eliminate files that align with our specified patterns. Here’s how we can include text and document files:
In this example, we will use the Get-ChildItem cmdlet to get all files from the C:\Temp folder. We will use the -Include parameter to include only .txt files.
Get-ChildItem -Path "C:\Temp\*" -Include *.txt
It’s also possible to specify multiple file extensions:
Get-ChildItem -Path C:\Documents\* -Include *.txt, *.csv
Get-ChildItem -Path C:\Documents\* -Exclude *.log, *.csv
In this example, we will use the Get-ChildItem cmdlet to get all files from the C:\Temp folder. We will use the -Exclude parameter to exclude .txt files.
Get-ChildItem -Path "C:\Documents\*" -Exclude *.txt
Let’s include specific file types and exclude certain files with specific names:
Get-ChildItem -Path "C:\Documents\*" -Include *.txt -Exclude log*
This command uses an asterisk as a wildcard, indicating any text file regardless of the name, with -Exclude specifically filtering out the ones starting with ‘error’.
Using Wildcards
Wildcard characters increase our command’s flexibility, allowing us to match file names or extension patterns. The * and ? are the most common wildcards, representing any string and a single character, respectively.
Get-ChildItem -Path "C:\Documents\*.txt" -Recurse
Recursive Searches
Get-ChildItem -Path "C:\Documents" -Recurse -Depth 2
With the -Force parameter, we can include items that are hidden files or marked as system files.
Get-ChildItem -Path "C:\Documents" -Recurse -Force
Select Properties
Get-ChildItem -Path C:\Folder | Select-Object Name,Length
Sort Files
Sorting files by the time they were last written to, utilizes the LastWriteTime property. This command organizes files beginning with the most recently modified:
Get-ChildItem -File | Sort-Object -Property LastWriteTime -Descending
To sort files by size, we leverage the Length property of files. To reverse the order and view larger files first, simply add the -Descending flag:
Get-ChildItem -File | Sort-Object Length -Descending
Copy Files to Backup
Let’s copy only .docx files over 30 days old to a backup location:
$Limit = (Get-Date).AddDays(-30)
Get-ChildItem -File *.docx -Recurse | Where { $_.LastWriteTime -lt $Limit } | Copy-Item -Destination D:\BackupsThis gets old files anywhere in the folder structure and copies them to another drive.
Export Files List to a File
Get-ChildItem -Path C:\Documents| Out-File filenames.txt
This command will save the list of files to a text file named “filename.txt” in the directory where PowerShell is running.
You can also export the results to a CSV file, using the “Export-Csv” cmdlet. For example, to export the results to a CSV file named “files.csv,” use:
Get-ChildItem -File | Export-Csv -Path Files.csv -NoTypeInformation
This command will create a CSV file in the current directory containing the file name, directory, and size of all files in the folder.

Looping Through Files in a Folder with PowerShell
When working with PowerShell, it is common to have scenarios where you need to perform actions on multiple files within a folder. PowerShell provides a simple and efficient way to accomplish this by utilizing a foreach loop. The foreach loop allows you to iterate through each file in a folder and perform specific actions on them, such as processing the file’s contents or modifying its properties.
Looping through Files in a Folder
To loop through files in a folder using PowerShell, you can use the Get-ChildItem cmdlet to retrieve all the files within the folder. You can then use a foreach loop to iterate through each file and perform the desired actions. Here’s an example:
$FolderPath = "C:\Documents"
#Get All files from a Folder's Root
$Files = Get-ChildItem -Path $FolderPath
#Iterate through Files
ForEach ($File in $Files) { # Perform actions on each file Write-Host "Processing file: $($File.Name)" }In this example, we first specify the path to the folder using the $folderPath variable. We then use the Get-ChildItem cmdlet to retrieve all the files within the folder and store them in the $files variable. Finally, we use a foreach loop (or ForEach-Object) to iterate through each file in the $files variable and perform the desired actions. In this case, we are simply displaying the name of each file using the Write-Host cmdlet, but you can replace this with any actions you need to perform.
Moving Files by Extension
Let’s get specific types of files and move them: Moving files with a specific extension, like .txt, to a new destination, can be achieved with:
Get-ChildItem -Path "C:\Backup" -Recurse -Filter *.txt | Move-Item -Destination "D:\Archive"
Using PowerShell to search for files in a folder
PowerShell provides several ways to search for files in a folder. One of the most common methods is to use the ‘-Filter’ parameter with the ‘Get-ChildItem’ cmdlet. This parameter allows you to specify a filter for the items to retrieve.
Get-ChildItem -Path 'C:\Documents' -Filter *log* -File
This command retrieves all files that contain the word ‘example’ in the ‘C:\Folder’ folder.
Common errors and how to troubleshoot them
When working with PowerShell, you may encounter some common errors. Here are a few of the most common errors and how to troubleshoot them:
- ‘Access Denied’ error: This error occurs when you don’t have permission to access a file or folder. To troubleshoot this error, make sure you have the appropriate permissions to access the file or folder.
- ‘File Not Found’ error: This error occurs when the file or folder you are trying to access doesn’t exist. To troubleshoot this error, make sure you have the correct path to the file or folder.
- ‘Invalid Argument’ error: This error occurs when you provide an invalid argument to a cmdlet. To troubleshoot this error, make sure you are providing valid arguments to the cmdlet.
Alternative methods for getting all files from a folder
While the ‘Get-ChildItem’ cmdlet is the most common method for retrieving files from a folder in PowerShell, there are alternative methods you can use. One such method is to use the ‘.NET Framework’ classes. Here is an example of how to retrieve all files in a folder using the ‘.NET Framework’ classes:
$Files = [System.IO.Directory]::GetFiles("C:\Documents")This command retrieves all files in the ‘C:\Documents’ folder using the ‘.NET Framework’ classes.

Conclusion
As you’ve learned, PowerShell provides a comprehensive set of commands and features for efficient file management and folder manipulation; retrieving all files from a folder is just one of its many capabilities. With the help of the Get-ChildItem cmdlet and other related commands, we can easily retrieve files and folders within our PowerShell scripts.
In this article, we discussed how to use the Get-ChildItem cmdlet to list files and folders, as well as how to filter the items based on various parameters. With a few simple commands, you can retrieve specific types of files, retrieve file properties, and even save the list of files to a text file. Additionally, we learned how to loop through files in a folder using a foreach loop, allowing us to perform actions on each individual file.
By leveraging these powerful features, we can streamline and automate our file management tasks with precision and efficiency. Whether we need to organize, backup, or process files and folders, PowerShell provides the tools necessary to accomplish our goals effectively.
How can I get files from a folder in PowerShell?
You can use the Get-ChildItem cmdlet to retrieve a list of all items within a specified folder, including files. This allows you to get files from a folder in PowerShell. For example, Get-ChildItem -Path C:\YourDirectory -File will return all the files in the specified directory without including subdirectories.
How do I list files and folders using Get-ChildItem in PowerShell?
By using the Get-ChildItem cmdlet, you can list files and folders in a directory, including subfolders. Get-ChildItem C:\Documents
This provides a comprehensive view of the contents of a folder in PowerShell.
Can I filter items with Get-ChildItem in PowerShell?
Yes, you can filter items retrieved from a folder using Get-ChildItem in PowerShell. You can filter items based on their name, extensions, attributes, and other properties to retrieve specific files or folders according to your requirements. For example, you can use the command Get-ChildItem -Filter *.txt"
To only retrieve items with a .txt extension.
How do I copy files and folders with PowerShell?
You can use the Copy-Item cmdlet in PowerShell to copy files and folders from one location to another. Simply specify the source and destination paths to perform the copy operation and efficiently manage and duplicate files and folders within your PowerShell scripts.Copy-Item -Path "C:\path\to\source.txt" -Destination "C:\path\to\destination"Copy-Item -Path "C:\path\to\source" -Destination "C:\path\to\destination" -Recurse
How can I create files and folders with PowerShell?
PowerShell offers the New-Item cmdlet to create new files and folders. By specifying the path and type of item you want to create, such as a file or directory, you can automate the creation of files and folders within your PowerShell scripts. E.g.,New-Item -ItemType File -Path "C:\path\to\example.txt"New-Item -ItemType Directory -Path "C:\path\to\new\folder"
What is the command to remove files and folders with PowerShell?
PowerShell provides the Remove-Item cmdlet to delete files and folders from a specified location. You can use this command to remove individual files or entire folders, including their contents, enabling you to clean up and remove unnecessary files and folders within your PowerShell scripts.
How do you export a list of file names from a directory to a text file using PowerShell?
How to retrieve just the filenames from a directory in PowerShell?
How can I get files recursively, including subfolders?
Use the -Recurse parameter with Get-ChildItem like:Get-ChildItem -File -Recurse
This will get all files recursively through all nested folders down the directory tree structure.
Why don’t I see file extensions in my output?
How can I filter files greater than a certain size?
$resourceGroupName = "xbackbonektadevmc-rg"
$storageAccName = "xfssaktamc601"
$fileShareName = "imagingcenter"
$directoryPath = "Software\KTA OPMT\KofaxTotalAgility-7.11 Software\KofaxTotalAgility-7.11.0.11_OPMT"
# Define the function to list directories and files recursively
Function GetFiles
{ param ( [string]$path ) Write-Host -ForegroundColor Green "Lists directories and files under $path.." ## Get the storage account context $ctx = $storageAccount.Context # Retrieve all files and folders under the file share $filesAndFolders = Get-AZStorageFile -Context $ctx -ShareName $fileShareName -Path $path ## Loop through files and folders foreach($item in $filesAndFolders) { # Check if the item is a directory if ($item.GetType().Name -eq "AzureStorageFileDirectory") { Write-Host -ForegroundColor Red "Folder Name: " $item.Name # Recursively call GetFiles function to list contents of subfolders if ($item.Path -like "$directoryPath\*") { GetFiles -path $item.Path } } else { # Display file name Write-Host -ForegroundColor Yellow "File Name: " $item.Name } }
}
# Start listing files and folders from the KofaxTotalAgility-7.11.0.11_OPMT folder
GetFiles -path $directoryPathI have tried executing the script it just display the name of the folder KofaxTotalAgility-7.11.0.11_OPMT but it is not listing the files and folders inside it
can you please help me adjust this script
You can use the script below to list both folder and file names using Azure PowerShell.
$resourceGroupName = "<Your-resource-grp name>"
$storageAccountName = "your-storage-account-name"
$fileShareName = "<Your-file-share-name>"
$directoryPath = "files/sample1"
$storageAccount = Get-AzStorageAccount -ResourceGroupName $resourceGroupName -Name $storageAccountName
$ctx = $storageAccount.Context
Function GetFiles
{ param ( [string]$path ) Write-Host -ForegroundColor Green "Lists directories and files under $path.." $ctx = $storageAccount.Context $filesAndFolders = Get-AZStorageFile -Context $ctx -ShareName $fileShareName -Path $path |Get-AZStorageFile foreach($item in $filesAndFolders) { if ($item.GetType().Name -eq "AzureStorageFileDirectory") { Write-Host -ForegroundColor Red "Folder Name: " $item.Name } } foreach($item in $filesAndFolders) { if ($item.GetType().Name -eq "AzureStorageFile") { Write-Host -ForegroundColor Yellow "File Name: " $item.Name } }
}
GetFiles -path $directoryPathLists directories and files under files/sample1..
Folder Name: sample2
Folder Name: sample3
File Name: 05-03-2024.html
File Name: 78089305.html
File Name: 78106201.html



