Поделиться через


Using the Convert-Path Cmdlet

Translating a Windows PowerShell Path

The Convert-Path cmdlet converts a Windows PowerShell path to a system path. What does that mean, and does it even matter? Well, suppose you’ve created a new Windows PowerShell drive (drive X). That drive letter is valid only in Windows PowerShell; you can’t switch to Windows Explorer and access drive X. Convert-Path, however, can tell you the “real” path of drive X. In other words, if you run this command:

Convert-Path x:

You’ll get back information similar to this:

C:\Scripts

This is particularly useful with registry drives. Windows PowerShell has its own syntax for indicating registry paths; for example, to use the Set-Location cmdlet to switch to the registry you would use a command similar to this:

Set-Location hkcu:\software\microsoft\windows

That’s fine, but outside of Windows PowerShell a path like hkcu:\software\microsoft\windows is meaningless. If you need to reference that path outside of Windows PowerShell, then just ask Convert-Path to lend you a hand:

Convert-Path hkcu:\software\microsoft\windows

That command gives you the actual path within the registry:

HKEY_CURRENT_USER\software\microsoft\windows
Convert-Path Aliases
  • cvpa