I am working on a build script using psake and I need to create an absolute path from the current working directory with an inputted path which could either be a relative or absolute path.
Suppose the current location is C:\MyProject\Build
$outputDirectory = Get-Location | Join-Path -ChildPath ".\output"
Gives C:\MyProject\Build\.\output, which isn't terrible, but I would like without the .\. I can solve that issue by using Path.GetFullPath.
The problem arises when I want to be able to provide absolute paths
$outputDirectory = Get-Location | Join-Path -ChildPath "\output"
Gives C:\MyProject\Build\output, where I need C:\output instead.
$outputDirectory = Get-Location | Join-Path -ChildPath "F:\output"
Gives C:\MyProject\Build\F:\output, where I need F:\output instead.
I tried using Resolve-Path, but this always complains about the path not existing.
I'm assuming Join-Path is not the cmdlet to use, but I have not been able find any resources on how to do what I want. Is there a simple one-line to accomplish what I need?