我需要一个查看目录的脚本,select在其内容中具有string并且长度(大小)为“8”的脚本。
我试图这样做,但不知何故,这是行不通的。 有小费吗?
Get-ChildItem -Path c:\test | Where-Object { $_.Length -eq 8 } | Select-String -pattern "foo" | group path | select name | foreach-object {remove-item $_.name}
我不确定你想要在这里使用group-object,从你所解释的那里来看,这是没有必要的。 正如所写,您还需要记住,当前目录可能不是c:\test因此您需要使用$_.fullname进行删除。
我想你的意思是这样做的:
Get-ChildItem -Path c:\test | Where-Object { $_.Length -eq 8 -and $_.name -match "foo"} | foreach-object {remove-item $_.fullname}