Launchers and Network Paths

I am invoking one of my scripts from a network path. Script basically only calls another program and passes it the current directory as an argument.

When I pass $ PWD as an argument, the path my program sees is "Microsoft.PowerShell.Core \ FileSystem :: \ my_server \ public" and it certainly fails because it expects a standard UNC path.

My ad hoc solution was simply to make .Replace("Microsoft.PowerShell.Core\FileSystem::", "") , and it worked, but I'm wondering what is the real way to convert the path from this "powershell" format to standard UNC.

Is there a better solution?

+4
source share
1 answer

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$ 

In addition, there is a -replace operator, you do not need this method call.

+10
source

Source: https://habr.com/ru/post/1389452/


All Articles