我是PowerShell的新手,并且在尝试查找某些类型的文件(.doc,.docx,.xls,.xlsx)时遇到困难,将文件名和大小(按文件扩展名分组)输出到文本文件,以及还包括每个文件扩展名的总数文件和总文件大小。
到目前为止我的代码是:
$Report_File_Destination = "C:\Users\StayPositibve\Desktop\testing20.txt"
$path = ".\*"
Get-ChildItem $path -Include *.doc, *.docx, *.xls, *.xlsx -Recurse | Group-Object Extension -NoElement | Out-File $Report_File_Destination -Append
每次运行此代码时,都会收到拒绝的Get-ChildItem访问权限(我以管理员身份运行PowerShell)。我究竟做错了什么?谢谢你的帮助!
答案 0 :(得分:0)
这是因为它存在一些不允许浏览的路径。您可以尝试使用Get-ChildItem的-ErrorAction Ignore -Force
选项来忽略这些错误,或强制访问用户无法访问的文件,例如隐藏文件或系统文件。在旧版本的PowerShell中,您可以测试-ErrorAction SilentlyContinue
。
Get-ChildItem $path -Include *.doc, *.docx, *.xls, *.xlsx -Recurse -ErrorAction Ignore -Force