PowerShell - get directory from full path

Let's say you have a full path of type string. E.g. the automatic variable $profile

write-host "Your PowerShell profile path is: " $profile
Your powershell profile path is: C:\Users\Richard\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1

This is how you get the parent directory of that path:

$parent= split-path $profile -Parent
write-host "Parent directory is: " $parent
Parent directory is: C:\Users\Richard\Documents\WindowsPowerShell

Ads by Google



Ask a question, send a comment, or report a problem - click here to contact me.

© Richard McGrath