Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Powershell and network paths

Tags:

powershell

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?

like image 644
Klark Avatar asked Dec 21 '22 04:12

Klark


1 Answers

Use $pwd.ProviderPath instead.

PS Home:\> cd \\localhost\h$
PS FileSystem::\\localhost\h$> $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.

like image 165
Joey Avatar answered Dec 29 '22 01:12

Joey