Join-Path would be a way to get the path to a nonexistent element that I consider. Something like that:
join-path $pwd $filename
Update:
I do not understand why you do not want to use .Net code. Powershell is .Net. All cmdlets are .Net code. The only valid reason for this is that when using .NET Code, the current directory is the directory from which Powershell was run, not $pwd
I simply list the ways in which I believe that this can be done so that you can deal with absolute and relational paths. None of them look simpler than GetFullPath() :
$ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($filename)
If you are concerned about the lack of an absolute path or not, you can do something like:
if(Split-Path $filename -IsAbsolute){ $filename } else{ join-path $pwd $filename
It's ugly
$item = Get-Item $filename -ea silentlycontinue if (!$item) { $error[0].targetobject } else{ $item.fullname }
A similar question, with similar answers: Powershell: allow a path that might not exist?
source share