Home » How to Get Full Path of Files Using Get-ChildItem in PowerShell

How to Get Full Path of Files Using Get-ChildItem in PowerShell

To retrieve the full path of items (files or directories) using the Get-ChildItem in PowerShell, you can access the FullName property of each item which provides the full path.

The following method shows how you can do it with syntax.

Method 1: Using the Get-ChildItem cmdlet with the FullName property

Get-ChildItem | Select-Object -Property FullName

This example will output the full paths of all files and folders in the current directory.

The following example shows how you can use this method.

How to Get Full Path Using the Get-ChildItem

To get the full path of files or folders using Get-Chidltem in PowerShell, you can use the FullName property for each item.

# specify the folder path
$folderPath = "C:\temp\log"

# get all files and folders in the specified directory with their full name

$items = Get-ChildItem -Path $folderPath -Recurse | Select-Object -Property FullName

# Output the full path
Write-Output $items

Output:

PowerShell get full path of items using get-childitem
PowerShell get full path of items using get-childitem

In this script, we defined a variable $folderPath that contains the directory path.

We then use the Get-ChildItem cmdlet in PowerShell to retrieve all files and folders recursively using the -Recurse parameter from the specified $folderPath.

The items returned from the Get-ChildItem cmdlet are piped to the Select-Object cmdlet to select the FullName property for each item. The results are stored in the $items variable.

Finally, we use the Write-Output cmdlet to output the full path of files or folders in the specified $folderPath.

After running the PowerShell script, it displays the full path of files and folders.

Get Full Path of Files Using Get-ChildItem with Filter in PowerShell

To get the full path of files that match specific criteria, you can use the -Filter parameter along with the Get-ChildItem cmdlet.

# specify the folder path
$folderPath = "C:\temp\log"

# get all files in the specified directory with their full name

$files = Get-ChildItem -Path $folderPath -Filter "*.txt" -Recurse | Select-Object -Property FullName

# Output the full path of files
Write-Output $files

Output:

PowerShell get full path of files using Get-ChildItem
PowerShell get full path of files using Get-ChildItem

In this script, it retrieves all .txt files in the specified $folderPath and its subfolders with their full paths.

Conclusion

I hope the above article on getting the full path with the Get-ChildItem cmdlet in PowerShell is helpful to you.

You can find more topics about Active Directory tools and PowerShell basics on the ActiveDirectoryTools home page.