【问题标题】:Piping results from on Powershell result to another将结果从 Powershell 结果传递到另一个
【发布时间】:2018-03-29 01:43:51
【问题描述】:

我正在尝试调试另一个开发人员的 powershell 脚本。这是运行 Powershell 5.1.16299.251 这是给我带来问题的代码行(由 --> 显示):

 $CurrentProfile = $profile
$ConcourseSettings = Get-ChildItem $PSSessionRoot\Audatex.B2B.ConcourseUtilities.*\content\scripts\ConcourseSettings.ps1 -File

    if($ConcourseSettings)
    {
        $ConcourseNugetPackage = Get-Item $PSSessionRoot\Audatex.B2B.ConcourseUtilities.*\content* 
   -->  $ConcourseScriptsPath = $ConcourseNugetPackage | Get-Item -Path scripts 
        $ConcourseProjectTemplatesDir = "$ConcourseNugetPackage\dotnet" | Get-ChildItem -Filter templates 
        $GitIgnoreFile = "$ConcourseNugetPackage\dotnet" | Get-ChildItem -Filter gitignore -File

        & $ConcourseSettings    
    }

如果我用 test-path 查看 $ConsourseSettings 变量,它确实显示为 true,所以我知道它正在获取该文件。这是我收到此错误的下一行:

Get-Item : 输入对象不能绑定到命令的任何参数,因为命令不接受管道输入,或者输入及其属性与接受管道输入的任何参数都不匹配。

非常感谢任何帮助。

【问题讨论】:

    标签: powershell


    【解决方案1】:

    您可以将可以转换为文件名字符串的对象通过管道传输到Get-Item,也可以指定-Path 参数。但是你不能两者都做,这就是你得到错误的原因。 PowerShell 不可能知道使用哪个值。

    我想您正在尝试将$ConcourseNugetPackage 文件的目录路径分配给$ConcourseScriptsPath。这样做:

    $ConcourseScriptsPath = $ConcourseNugetPackage.DirectoryName
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-05
      • 2015-12-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多