Powershell - Difference between -Path and -LiteralPath, -Name and -LiteralName parameters

To support me, you can subscribe to the channel, share and like the videos, disable your ad blocker or make a donation. Thank you!

Hello,

The difference between the -Path and -LiteralPath, -Name and -LiteralName parameters lies in whether or not wildcards (*?[]) are supported.

Let’s check this with a few commands

# Test the following commands:
get-item -LiteralPath C:\Windows\System
get-item -Path C:\Windows\System
# There is no difference
# Test the following commands:
get-item -LiteralPath C:\Windows\System??
get-item -Path C:\Windows\System??
-LiteralPath does not work with wildcards
# You can check this by looking at the help
Get-Help Get-Item
"-LiteralPath <System.String[]>"
"..."
"Accept wildcards? false"
"-Path <System.String[]>"
"..."
"Accept wildcards? True"
# Let's do a test by creating 2 folders
mkdir c:\book
mkdir c:\look
# Use wildcards to find the 2 folders
Get-Item -Path c:\[bl]ook
# Both folders are displayed
Get-Item -LiteralPath c:\[bl]ook
# Aucun résultat
# Another test (characters [] are allowed in folder and file names)
mkdir c:\[bl]ook
Get-Item -LiteralPath c:\[bl]ook
# The folder is displayed

The principle is the same with the -Name and -LiteralName parameters.

Related links