Convert-Path
将路径从 PowerShell 路径转换为 PowerShell 提供程序路径。
语法
Convert-Path
[-Path] <String[]>
[<CommonParameters>]
Convert-Path
-LiteralPath <String[]>
[<CommonParameters>]
说明
该 Convert-Path
cmdlet 将路径从 PowerShell 路径转换为 PowerShell 提供程序路径。
示例
示例 1:将工作目录转换为标准文件系统路径
此示例将当前工作目录(由点 () .
表示)转换为标准 FileSystem 路径。
PS C:\> Convert-Path .
C:\
示例 2:将提供程序路径转换为标准注册表路径
此示例将 PowerShell 提供程序路径转换为标准注册表路径。
PS C:\> Convert-Path HKLM:\Software\Microsoft
HKEY_LOCAL_MACHINE\Software\Microsoft
示例 3:将路径转换为字符串
此示例将路径转换为当前提供程序的主目录(即 FileSystem 提供程序)的字符串。
PS C:\> Convert-Path ~
C:\Users\User01
参数
-LiteralPath
指定要转换的路径(作为一个字符串数组)。 LiteralPath 参数的值完全按类型化使用。 不会将任何字符解释为通配符。 如果路径包括转义符,请将其括在单引号中。 单引号指示 PowerShell 不要将任何字符解释为转义序列。
Type: | String[] |
Aliases: | PSPath, LP |
Position: | Named |
Default value: | None |
Required: | True |
Accept pipeline input: | True |
Accept wildcard characters: | False |
-Path
指定要转换的 PowerShell 路径。
Type: | String[] |
Position: | 0 |
Default value: | None |
Required: | True |
Accept pipeline input: | True |
Accept wildcard characters: | False |
输入
可以通过管道将路径(但不是文本路径)传递给此 cmdlet。
输出
此 cmdlet 返回一个包含已转换的路径的字符串。
备注
包含 Path 名词的 cmdlet 操作路径名称,并返回所有 PowerShell 提供程序都可以解释的简洁格式的名称。 这些 cmdlet 用于需要在其中以特定格式显示全部或部分路径名称的程序或脚本中。 使用它们就像使用 Dirname、Normpath、Realpath、Join 或其他路径操作器一样。
可以将路径 cmdlet 与某些提供程序一起使用,包括 FileSystem、Registry 和 Certificate 提供程序。
此 cmdlet 用于处理由任何提供程序公开的数据。 若要列出会话中可用的提供程序,请键入 Get-PSProvider
。 有关详细信息,请参阅 about_Providers。
Convert-Path
仅转换现有路径。 它不能用于转换尚不存在的位置。