Categories

Path cmdlets: 6 Convert-Path

The last of the path cmdlets is Convert-Path. 

The Convert-Path cmdlet converts a path from a Windows PowerShell path to a Windows PowerShell provider path.

I can’t remember using this one.  Building on the examples in the help file we can expand the current folder.

PS> Convert-Path -Path .
C:\scripts

We can expand a registry path

PS> Convert-Path -Path HKLM:\software\Microsoft
HKEY_LOCAL_MACHINE\software\Microsoft

The certificate store doesn’t give us much.

PS> Convert-Path -Path cert:\localmachine\ca
\localmachine\ca

 

One interesting thought is the Windows 2008 R2 AD provider – but convert-path doesn’t appear to work. Shame would have been a good way to get a distinguished name however

PS> Split-Path -Path (Get-Location) -NoQualifier
\ou=servers,DC=Manticore,DC=org

is close and

PS> (Split-Path -Path (Get-Location) -NoQualifier ).SubString(1)
ou=servers,DC=Manticore,DC=org

is even closer.

PS> Split-Path -Path (Get-Location) -Leaf
ou=servers

gives the current OU

and

PS> (Split-Path -Path (Get-Location) -Parent ).SubString(3)
DC=Manticore,DC=org

should give the parent.

Leave a Reply