Convert-Path
將路徑從 PowerShell 路徑轉換為 PowerShell 提供者路徑。
Syntax
Convert-Path
[-Path] <String[]>
[<CommonParameters>]
Convert-Path
-LiteralPath <String[]>
[<CommonParameters>]
Description
Cmdlet 會將 Convert-Path
路徑從 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不要將任何字元解譯為逸出序列。
如需詳細資訊,請參閱 about_Quoting_Rules。
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: | True |
輸入
您可以使用管線將路徑 (而非常值路徑) 傳送至此 Cmdlet。
輸出
此 Cmdlet 會傳回包含已轉換路徑的字串。
備註
PowerShell 包含下列的 Convert-Path
別名:
- 所有平台:
cvpa
包含 Path 名詞的 Cmdlet 會操作路徑名稱,並以精簡格式傳回所有 PowerShell 提供者可以解譯的名稱。 其設計目的是要在您想要以特定格式顯示路徑的所有或部分的程式和腳本中使用。 使用它們就像使用 Dirname、Normpath、Realpath、Join 或其他路徑操作工具一樣。
您可以使用路徑 Cmdlet 搭配數個提供者,包括 FileSystem、 登錄和 憑證 提供者。
此 Cmdlet 是針對與任何提供者公開的資料搭配使用所設計。 若要列出工作階段中可用的提供者,請輸入 Get-PSProvider
。 如需詳細資訊,請參閱 about_Providers。
Convert-Path
只會轉換現有的路徑。 它無法用來轉換尚未存在的位置。