Powershell 和网络路径

标签 powershell

我正在从网络路径调用我的脚本之一。脚本基本上只调用另一个程序并将当前目录作为参数传递给它。

当我将 $PWD 作为参数传递时,我的程序看到的路径是“Microsoft.PowerShell.Core\FileSystem::\my_server\public”,它当然会失败,因为它需要标准的 UNC 路径。

我的临时解决方案是简单地执行 .Replace("Microsoft.PowerShell.Core\FileSystem::", "") 并且它有效,但我想知道将路径从这种“powershell”格式转换为标准 UNC 的真正方法是什么。

有更好的解决方案吗?

最佳答案

请改用 $pwd.ProviderPath

PS Home:\> cd \\localhost\h$
PS FileSystem::\\localhost\h$> $pwd|fl -force *


Drive        :
Provider     : FileSystem
ProviderPath : \\localhost\h$
Path         : FileSystem::\\localhost\h$

此外,还有一个 -replace 运算符,您不一定需要该方法调用。

关于Powershell 和网络路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8742372/

相关文章:

xml - 嵌套的 XML Powershell

powershell - 使用 powershell 将 <clear/> 元素添加到 WebDAV authoringRules

powershell - 可以在 powershell 脚本上设置最大内存消耗(以%或兆字节为单位)吗?

json - 格式化 Invoke-RestMethod 或 ConvertFrom-Json 返回的 [pscustomobject] 实例

powershell - 如何在 Powershell 中获取所有 Azure VM 的列表

.net - 通过 NuGet 提供命令行工具以在 Visual Studio 中的生成后事件中使用

Azure Powershell - 根据私有(private)IP查找NIC

powershell - 使用Powershell重命名目录中具有给定名称的所有文件夹

shell - 如何使用 Bash shell 命令使 npm 项目在 Windows 上工作?

powershell - "Get-ADGroupMember | Get-ADUser"对不同域中的用户失败