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
上面的脚本可以正常工作,现在我想把它和下面的脚本合并成一个脚本:
$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
任何人都可以帮助我吗?