如何解决这个问题?,我正在编写一段代码,它将复制所有单个文件类型(即。txt,jpg等)到一个单一的位置,这样我就可以找出副本并在一个地方操作它们。最后,我能够列出除systemroot之外的所有物理驱动器,递归地搜索每个驱动器以查找文件,并列出它们。例子如下:
#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
,其结果是
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
太棒了!代码工作得很好。好吧..。直到我试图操纵那份清单。
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!!!
长篇大论,我知道,它可能已经被回答在哪里,除非我所有的搜索,我找不到钥匙。我尝试的一切都返回对象,而不是文本。
发布于 2022-07-17 18:41:09
在我看来,最终的管道项目是一个ft
,所以输出对象是一个格式化的表,而不是您想要的对象。
我会把它移除,再试一次:
|ft fullname -autosize -HideTableHeaders
https://stackoverflow.com/questions/73016786
复制相似问题