我正在创建一个工具,我们的服务台,以复制频繁的决议评论,他们可能使用时,解决票。我目前有:
Get-ChildItem ".\FileStore" | Out-GridView -PassThru -Title "Quick Notes" | Get-Content | Set-Clipboard它输出类似于(但在GridView中)的内容:
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列输出,但是我不确定如何实现这一点。我尝试过不起作用的Select、Select-Object和Format-Table,因为我收到以下信息:
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?
发布于 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表示默认显示哪些属性。
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发布于 2018-11-15 19:06:05
这看起来非常像我对用户deleted question的回答,用户Adam部分地出现在follow-up question中。
我的答案(另一条路)是:
Get-ChildItem -Path ".\FileStore" |
Select-Object Name,FullName |
Out-GridView -PassThru -Title "Quick Notes"|
ForEach-Object{Get-Content $_.Fullname | Set-Clipboard -Append}https://stackoverflow.com/questions/53323526
复制相似问题