| external help file | Microsoft.PowerShell.Commands.Management.dll-Help.xml | |
|---|---|---|
| Locale | en-US | |
| Module Name | Microsoft.PowerShell.Management | |
| ms.date | 09/25/2024 | |
| online version | https://learn.microsoft.com/powershell/module/microsoft.powershell.management/resolve-path?view=powershell-7.6&WT.mc_id=ps-gethelp | |
| schema | 2.0.0 | |
| aliases |
|
|
| title | Resolve-Path |
Resolves the wildcard characters in a path, and displays the path contents.
Resolve-Path [-Path] <string[]> [-Relative] [-RelativeBasePath <string>]
[-Credential <pscredential>] [-Force] [<CommonParameters>]
Resolve-Path -LiteralPath <string[]> [-Relative] [-RelativeBasePath <string>]
[-Credential <pscredential>] [-Force] [<CommonParameters>]
The Resolve-Path cmdlet displays the items and containers that match the wildcard pattern at the
location specified. The match can include files, folders, registry keys, or any other object
accessible from a PSDrive provider.
The tilde character (~) is shorthand notation for the current user's home folder. This example
shows Resolve-Path returning the fully qualified path value.
Resolve-Path ~Path
----
C:\Users\User01
Resolve-Path -Path "windows"Path
----
C:\Windows
When run from the root of the C: drive, this command returns the path of the Windows folder in
the C: drive.
"C:\windows\*" | Resolve-PathThis command returns all the files and folders in the C:\Windows folder. The command uses a
pipeline operator (|) to send a path string to Resolve-Path.
Resolve-Path -Path "\\Server01\public"This command resolves a Universal Naming Convention (UNC) path and returns the shares in the path.
Resolve-Path -Path "C:\prog*" -Relative.\Program Files
.\Program Files (x86)
.\programs.txt
This command returns relative paths for the directories at the root of the C: drive.
This example uses the LiteralPath parameter to resolve the path of the Test[xml] subfolder.
Using LiteralPath causes the brackets to be treated as normal characters rather than a regular
expression.
Resolve-Path -LiteralPath 'test[xml]'This example uses the RelativeBasePath parameter to resolve the path of the pwsh executable
relative to $Env:TEMP. When the command includes the Relative switch parameter, it returns a
String representing the relative path from $Env:TEMP to the pwsh executable.
$ExecutablePath = Get-Command -Name pwsh | Select-Object -ExpandProperty Source
Resolve-Path -Path $ExecutablePath -RelativeBasePath $Env:TEMP -Relative..\..\..\..\..\Program Files\PowerShell\7\pwsh.exe
Example 8: Resolve paths for hidden items
By default, Resolve-Path does not return hidden items. This example uses the Force parameter
to resolve hidden items. The Get-Item command confirms that the .git folder is hidden. Using
Resolve-Path without the Force parameter returns only the visible items. Adding the Force
parameter returns all items, including hidden items.
PS> Get-Item .git -Force
Directory: D:\Git\PS-Docs\PowerShell-Docs
Mode LastWriteTime Length Name
---- ------------- ------ ----
d--h- 9/25/2024 4:46 PM .git
PS> Resolve-Path .git*
Path
----
D:\Git\PS-Docs\PowerShell-Docs\.github
D:\Git\PS-Docs\PowerShell-Docs\.gitattributes
D:\Git\PS-Docs\PowerShell-Docs\.gitignore
PS> Resolve-Path .git* -Force
Path
----
D:\Git\PS-Docs\PowerShell-Docs\.git
D:\Git\PS-Docs\PowerShell-Docs\.github
D:\Git\PS-Docs\PowerShell-Docs\.gitattributes
D:\Git\PS-Docs\PowerShell-Docs\.gitignoreSpecifies a user account that has permission to perform this action. The default is the current user.
Type a user name, such as User01 or Domain01\User01, or pass a PSCredential object. You can
create a PSCredential object using the Get-Credential cmdlet. If you type a user name, this
cmdlet prompts you for a password.
This parameter is not supported by any providers installed with PowerShell.
Type: System.Management.Automation.PSCredential
Parameter Sets: (All)
Aliases:
Accepted values:
Required: False
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: FalseAllows the cmdlet to get items that otherwise can't be accessed by the user, such as hidden or system files. The Force parameter doesn't override security restrictions. Implementation varies among providers. For more information, see about_Providers.
This parameter was added in PowerShell 7.5-preview.5.
Type: System.Management.Automation.SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: FalseSpecifies the path to be resolved. The value of the LiteralPath parameter is used exactly as
typed. No characters are interpreted as wildcard characters. If the path includes escape characters,
enclose it in single quotation marks ('). Single quotation marks tell PowerShell not to interpret
any characters as escape sequences.
Type: System.String[]
Parameter Sets: LiteralPath
Aliases: PSPath, LP
Accepted values:
Required: True
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: FalseSpecifies the PowerShell path to resolve. This parameter is required. You can also pipe a path
string to Resolve-Path. Wildcard characters are permitted.
Type: System.String[]
Parameter Sets: Path
Aliases:
Accepted values:
Required: True
Position: 0
Default value: None
Accept pipeline input: True (ByPropertyName, ByValue)
Accept wildcard characters: TrueIndicates that this cmdlet returns a relative path.
Type: System.Management.Automation.SwitchParameter
Parameter Sets: Path, LiteralPath
Aliases:
Accepted values:
Required: True (None) False (Path, LiteralPath)
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: FalseSpecifies a path to resolve the relative path from. When you use this parameter, the cmdlet returns the System.Management.Automation.PathInfo object for the resolved path.
When you use this parameter with the Relative switch parameter, the cmdlet returns a string representing the relative path from RelativeBasePath to Path.
This parameter was added in PowerShell 7.4.
Type: System.String
Parameter Sets: (All)
Aliases:
Accepted values:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: FalseThis cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.
You can pipe a string that contains a path to this cmdlet.
By default, this cmdlet returns a PathInfo object.
If you specify the Relative parameter, this cmdlet returns a string value for the resolved path.
PowerShell includes the following aliases for Resolve-Path:
- All platforms:
rvpa
The *-Path cmdlets work with the FileSystem, Registry, and Certificate providers.
Resolve-Path is designed to work with any provider. To list the providers available in your
session, type Get-PSProvider. For more information, see
about_Providers.
Resolve-Path only resolves existing paths. It cannot be used to resolve a location that does not
exist yet.