首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >选择-Object和Out-GridView

选择-Object和Out-GridView
EN

Stack Overflow用户
提问于 2018-11-15 16:10:17
回答 2查看 2.4K关注 0票数 0

我正在创建一个工具,我们的服务台,以复制频繁的决议评论,他们可能使用时,解决票。我目前有:

代码语言:javascript
复制
Get-ChildItem ".\FileStore" | Out-GridView -PassThru -Title "Quick Notes" | Get-Content | Set-Clipboard

它输出类似于(但在GridView中)的内容:

代码语言:javascript
复制
Mode                LastWriteTime         Length Name                                                                                                                                          
----                -------------         ------ ----                                                                                                                                          
-a----       15/11/2018     14:38             14 1.txt                                                                                                                                         
-a----       15/11/2018     14:39             14 2.txt                                                                                                                                         
-a----       15/11/2018     14:39             14 3.txt                                                                                                                                         
-a----       15/11/2018     14:39             14 4.txt 

我的目标是让Name列输出,但是我不确定如何实现这一点。我尝试过不起作用的SelectSelect-ObjectFormat-Table,因为我收到以下信息:

代码语言:javascript
复制
Get-Content : The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of 
the parameters that take pipeline input.

是否可以只将Name列输出到GridView?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-11-15 19:14:42

要允许Get-Content找到文件,您需要选择的不仅仅是一个Name,因为Get-Content无法解释Name属性。它没有匹配的参数。最好的选择是PSPath属性,它包含完全限定的PowerShell路径?并将匹配LiteralPath cmdlet的Get-Content参数。

遗憾的是,Out-GridView没有指定显示哪些属性的直接方法,但它使用标准的PowerShell机制来选择它们。所以我们可以用它代替。要做到这一点,您需要将MemberSet属性PSStandardMembers附加到属性集DefaultDisplayPropertySet,属性集DefaultDisplayPropertySet表示默认显示哪些属性。

代码语言:javascript
复制
Get-ChildItem ".\FileStore" |
Select-Object Name, PSPath |
Add-Member -MemberType MemberSet `
           -Name PSStandardMembers `
           -Value ([System.Management.Automation.PSPropertySet]::new(
                      'DefaultDisplayPropertySet',
                      [string[]]('Name')
                  )) `
           -PassThru |
Out-GridView -PassThru -Title "Quick Notes" |
Get-Content | Set-Clipboard
票数 1
EN

Stack Overflow用户

发布于 2018-11-15 19:06:05

这看起来非常像我对用户deleted question的回答,用户Adam部分地出现在follow-up question中。

我的答案(另一条路)是:

代码语言:javascript
复制
Get-ChildItem -Path ".\FileStore" |
  Select-Object Name,FullName |
    Out-GridView -PassThru -Title "Quick Notes"|
      ForEach-Object{Get-Content $_.Fullname | Set-Clipboard -Append}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53323526

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档