首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >如何在powershell中而不是在对象中返回搜索项的值?

如何在powershell中而不是在对象中返回搜索项的值?
EN

Stack Overflow用户
提问于 2022-07-18 02:34:50
回答 1查看 35关注 0票数 0

如何解决这个问题?,我正在编写一段代码,它将复制所有单个文件类型(即。txt,jpg等)到一个单一的位置,这样我就可以找出副本并在一个地方操作它们。最后,我能够列出除systemroot之外的所有物理驱动器,递归地搜索每个驱动器以查找文件,并列出它们。例子如下:

代码语言:javascript
代码运行次数:0
运行
复制
 #TFT  - This File Type
    #This bit find all hard drives and jump drives, lists files of the extension given
    #and returns that list of files.
    
    function tft($ext){
        $thisvalue = ($ext)
        $just_drives = @(get-psdrive |where root -Like '*`:`\'|where  Used* -gt ''|where name -NE 'c')
    
    if($ext -notlike '`*.*'){$ext='*.'+$ext}
    
    $a=foreach($jd in $just_drives){set-location -path $jd.Root;gci $ext -Recurse -Force -ErrorAction SilentlyContinue|where fullname -NotLike '*RECYCLE.BIN*'|ft fullname -autosize -HideTableHeaders
    
    
    }}
PS:>tft ttf

,其结果是

代码语言:javascript
代码运行次数:0
运行
复制
PS:>$a [enter]
    [truncated for space]
    E:\$WINDOWS.~BT\Windows\Boot\Fonts\chs_boot.ttf                                                                       
    E:\$WINDOWS.~BT\Windows\Boot\Fonts\cht_boot.ttf                                                                       
    E:\$WINDOWS.~BT\Windows\Boot\Fonts\jpn_boot.ttf                                                                       
    E:\$WINDOWS.~BT\Windows\Boot\Fonts\kor_boot.ttf                                                                       
    E:\$WINDOWS.~BT\Windows\Boot\Fonts\malgunn_boot.ttf                                                                                                                             
    ...
    H:\WINX21H2\efi\microsoft\boot\fonts\segoe_slboot.ttf  
    H:\WINX21H2\efi\microsoft\boot\fonts\wgl4_boot.ttf     
    H:\WINX21H2\sources\segoeui.ttf

太棒了!代码工作得很好。好吧..。直到我试图操纵那份清单。

代码语言:javascript
代码运行次数:0
运行
复制
    PS:> write-host $a -join(',')
        Microsoft.PowerShell.Commands.Internal.Format.FormatStartData,Microsoft.PowerShell.Commands.Internal.Format.GroupStartData,Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData,Microsoft.PowerShell.Commands.Internal.Format...
PS:> $a|copy-item d:\
copy : 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.
At line:1 char:4
+ $a|copy d:\
+    ~~~~~~~~
    + CategoryInfo          : InvalidArgument: (Microsoft.Power...FormatStartData:PSObject) [Copy-Item], ParameterBin 
   dingException
    + FullyQualifiedErrorId : InputObjectNotBound,Microsoft.PowerShell.Commands.CopyItemCommand....
... for 337K+ lines!!!

长篇大论,我知道,它可能已经被回答在哪里,除非我所有的搜索,我找不到钥匙。我尝试的一切都返回对象,而不是文本。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-07-18 02:41:09

在我看来,最终的管道项目是一个ft,所以输出对象是一个格式化的表,而不是您想要的对象。

我会把它移除,再试一次:

代码语言:javascript
代码运行次数:0
运行
复制
|ft fullname -autosize -HideTableHeaders
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73016786

复制
相关文章

相似问题

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