PowerShell PSCX 读取存档:无法绑定参数...问题

发布于 2024-09-06 05:44:20 字数 1623 浏览 6 评论 0原文

我遇到了一个问题,我似乎无法使用通过 PowerShell 社区扩展 (v2.0.3782.38614) 提供的 Read-Archive cmdlet 来解决这个问题。

这是一个用于展示我遇到的问题的缩减示例:

$mainPath = "p:\temp"
$dest = Join-Path $mainPath "ps\CenCodes.zip"
Read-Archive -Path $dest -Format zip

运行上面的代码会产生以下错误:

Read-Archive : Cannot bind parameter 'Path'. Cannot convert the "p:\temp\ps\CenCodes.zip" value of type "System.String" to type "Pscx.IO.PscxPathInfo".
At line:3 char:19
+ Read-Archive -Path <<<<  $dest -Format zip
    + CategoryInfo          : InvalidArgument: (:) [Read-Archive], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Pscx.Commands.IO.Compression.ReadArchiveCommand

如果我不使用 Join-Path 来构建传递给 Read-Archive 的路径,它就可以工作,如本示例所示:

$mainPath = "p:\temp"
$path = $mainPath + "\ps\CenCodes.zip"
Read-Archive -Path $path -Format zip

上面的输出:

    ZIP Folder: CenCodes.zip#\

Index          LastWriteTime         Size    Ratio Name                                                                                       -----          -------------         ----    ----- ----
0         6/17/2010  2:03 AM      3009106  24.53 % CenCodes.xls

更令人困惑的是,如果我比较上面两个读取存档示例中作为 Path 参数传递的两个变量,它们看起来相同:

这...

Write-Host "dest=$dest"
Write-Host "path=$path"
Write-Host ("path -eq dest is " + ($dest -eq $path).ToString())

输出...

dest=p:\temp\ps\CenCodes.zip
path=p:\temp\ps\CenCodes.zip
path -eq dest is True

任何人都对为什么第一个示例有任何想法抱怨但第二个工作正常吗?

I'm running across a problem I can't seem to wrap my head around using the Read-Archive cmdlet available via PowerShell Community Extensions (v2.0.3782.38614).

Here is a cut down sample used to exhibit the problem I'm running into:

$mainPath = "p:\temp"
$dest = Join-Path $mainPath "ps\CenCodes.zip"
Read-Archive -Path $dest -Format zip

Running the above produces the following error:

Read-Archive : Cannot bind parameter 'Path'. Cannot convert the "p:\temp\ps\CenCodes.zip" value of type "System.String" to type "Pscx.IO.PscxPathInfo".
At line:3 char:19
+ Read-Archive -Path <<<<  $dest -Format zip
    + CategoryInfo          : InvalidArgument: (:) [Read-Archive], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Pscx.Commands.IO.Compression.ReadArchiveCommand

If I do not use Join-Path to build the path passed to Read-Archive it works, as in this example:

$mainPath = "p:\temp"
$path = $mainPath + "\ps\CenCodes.zip"
Read-Archive -Path $path -Format zip

Output from above:

    ZIP Folder: CenCodes.zip#\

Index          LastWriteTime         Size    Ratio Name                                                                                       -----          -------------         ----    ----- ----
0         6/17/2010  2:03 AM      3009106  24.53 % CenCodes.xls

Even more confusing is if I compare the two variables passed as the Path argument in the two Read-Archive samples above, they seem identical:

This...

Write-Host "dest=$dest"
Write-Host "path=$path"
Write-Host ("path -eq dest is " + ($dest -eq $path).ToString())

Outputs...

dest=p:\temp\ps\CenCodes.zip
path=p:\temp\ps\CenCodes.zip
path -eq dest is True

Anyone have any ideas as to why the first sample gripes but the second one works fine?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

美羊羊 2024-09-13 05:44:20

我在 PSCX CodePlex 主页上的问题跟踪器中创建了一个项目。显然这是 PscxPathInfo 当前的已知问题。 (请参阅 PSCX 问题跟踪器中的项目 #28023)。

解决方法是这样做:

Get-Item $dest | Read-Archive 

归功于 CodePlex 上的 r_keith_hill 的特定解决方法。

I created an item in the issue tracker on the CodePlex home of PSCX. Apparently this is a current known issue with PscxPathInfo. (See item #28023 in the PSCX Issue Tracker).

A work around is to do this:

Get-Item $dest | Read-Archive 

Credit to r_keith_hill on CodePlex for that particular work around.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文