Question:
I am calling one of my scripts from a network path. Script basically only calls another program and passes to it the current directory as an argument.
When I pass $PWD as an argument, the path that my program sees is “Microsoft.PowerShell.Core\FileSystem::\my_server\public”, and it of course fails because it expects standard UNC path.
My ad hoc solution was to simply do .Replace("Microsoft.PowerShell.Core\FileSystem::", "")
and it worked, but I wonder what is the real way to convert path from this “powershell” format to the standard UNC.
Is there a better solution?
Answer:
Use $pwd.ProviderPath
instead.
1 2 3 |
PS Home:\> cd \\localhost\h$ PS FileSystem::\\localhost\h |
gt; $pwd|fl -force *
Drive :
Provider : FileSystem
ProviderPath : \\localhost\h$
Path : FileSystem::\\localhost\h$
Besides, there is a -replace
operator, you don’t necessarily need that method call.