Get-ChildItem -recurse | Where {!$_.PSIsContainer -and `
$_.LastWriteTime -lt (get-date).AddDays(-31)} | Remove-Item -whatif
Get-ChildItem -recurse | Where {$_.PSIsContainer -and `
@(Get-ChildItem -Lit $_.Fullname -r | Where {!$_.PSIsContainer}).Length -eq 0} |
Remove-Item -recurse -whatif
上記のスクリプトは適切に機能します。次は、それを次のスクリプトと組み合わせて 1 つのスクリプトにします。
$path = "<path to file>"
$shell = new-object -comobject "Shell.Application"
$item = $shell.Namespace(0).ParseName("$path")
$item.InvokeVerb("delete")
これが私の結合されたスクリプトです:
Get-ChildItem -recurse | Where {$_.PSIsContainer -and `
@(Get-ChildItem -Lit $_.Fullname -r | Where {!$_.PSIsContainer}).Length -eq 0} |
$path = $_.Fullname
$shell = new-object -comobject "Shell.Application"
$item = $shell.Namespace(0).ParseName("$path")
$item.InvokeVerb("delete") -recurse -whatif
しかし、私はいつもエラーメッセージを受け取ります:
Expressions are only allowed as the first element of a pipeline.
At line:3 char:7
You must provide a value expression on the right-hand side of the '-' operator.
At line:6 char:28
Unexpected token 'recurse' in expression or statement.
At line:6 char:29
Unexpected token '-whatif' in expression or statement.
At line:6 char:37
誰でも私を助けることができますか?