powershell - 没有输出Powershell脚本

标签 powershell powershell-3.0

运行该脚本时没有输出。我认为这很明显,但是尽管它创建了test.txt,但是在删除的文件中没有数据!

提前致谢

$limit = (Get-Date).AddDays(-7) 
Get-ChildItem 'C:\temp' -Recurse | 
Where-Object {
 -not $_.PSIsContainer -and $_.CreationTime -lt $limit 
} |  Remove-Item | Out-File -FilePath c:\text.txt

最佳答案

Remove-Item没有输出。您可以启用Remove-Item的详细输出,然后将Verbose流重定向到标准输出流,如下所示:

... | Remove-Item -Verbose 4>&1 > c:\text.txt

关于powershell - 没有输出Powershell脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18830726/

相关文章:

powershell - 在远程 session 中使用替代凭据启动进程

powershell - 使用 invoke-restmethod 时设置主机头

function - PowerShell更改返回对象的类型

c# - 如何通过脚本模拟 AWS Toolkit for Visual Studio 中的构建和部署功能?

image - invoke-webrequest获取带有图像的完整网页

xml - 为PowerShell脚本异常的结果添加颜色

Powershell - 删除除特定子目录中的项目之外的所有项目

email - Powershell 发送带图片的电子邮件

.net - 为什么 "net use */delete"不起作用但在我的 PowerShell 脚本中等待确认?

arrays - 使用流水线将字符串拆分为多维数组